Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 3 Fanny, the fone directory fairy, has compiled a fone directory containing the 8-digit cellfone numbers of all the earthling-protector fairies in Fairy
Question 3 Fanny, the fone directory fairy, has compiled a fone directory containing the 8-digit cellfone numbers of all the earthling-protector fairies in Fairy World, so that the earthlings can easily contact their personal protector fairies and request help for their life on earth. For security reasons, the cellfone numbers of the protector fairies are encoded before they are added to the fone directory, since Fanny is worried that the prankster fairies can get hold of the protector fairies' fone numbers and make prank calls, or try to add their own fone numbers into the protector fairies' fone directory. Before each new number is added into the fone directory, the fone number's validity is checked and then it is encoded and printed. Write a Python program, in a file called fairy_fones.py, to check the validity of a series of fairy cellfone numbers and to encode and display only the valid fone numbers. Your program should include the following functions: function main which obtains a series of fone numbers as strings of digits, until "nomore" is entered; for each number, it checks to see if it is a valid protector fairy cellfone number or not (it prints a message if it is not), and if it is valid, it encodes the number and prints it. The main function does this using the following functions to process each fone number: o function isValid which takes a fone number and checks to see if the given fone number is a valid protector fairy fone number; the function returns True if the given fone number is valid, otherwise it returns False. A fone number is valid if it is exactly 8 digits long and if it does not include the digits 0 or 9. For example, 23415467 is a valid fairy cellfone number, but 65781098 and 6588848765 are 4 invalid, prankster fairy fone numbers. You may assume that all of the fone number strings will contain only the digits '0' to '9' (no letters or other symbols). o function codeNum which, given a (already checked for validity) fone number, codes the given fone number into an equal length string of captial letters and prints the result. The encoding can be done as follows: get the ordinal value (ASCII character code, see partial ASCII table below) of each digit add an offset of 20 to that value to get the character code of a corresponding capital letter convert the new code back to a character (capital letter) Hint: The ord () funct will give the ordinal (ASCII character code) value of a given character. The chr () function returns the ASCII character for a given integer value. For example, ord ('1') will return 49 and chr (65) will return A. Dec Chr Dec '0' 6 49 55 Chr Dec '1' '7' = 48 50 54 56 60 61 62 '>1 66 'B' 67 'C' 68 72 'H' 73 'I' 74 78 'N' 79 '0' 80 84 'T' 85 'U' 90 'Z' 91 '[' 96 11 97 'a' 2 20 Chr 2 '8' 92 2010 'P' 86 'V' '\' 98 'b' 102 'f' 103 'g' 104 'h' 108 '1' 109 'm' 110 'n' 'D' 'J' 114 'r' 115 's' 116 120 x 121 'y' 122 'z' Dec 79955SELTR 51 '3' 57 '9' 63 '2' 'E' 70 'K' 76 'Q' 82 'W' 88 ']' 69 75 18 81 87 93 105 111 Chr Dec Chr Dec Chr 52 '4' 53 5' 58 59 ';' 64 '@' 65 'A' 'F' 71 'G' 'L 77 'M' 83 S 89 'Y' 95 'C' 100 'd' 101 'e' 'i' 106 j 107 'k' 112 'p' 113 'q' 'o' 'u' 118 'v'. 119 'W' 't' 117 340 94 'R' 'X' TAI 1 T Note: You should use only the user-defined functions (as described above), along with loops, decision structures and the built-in functions input (), range (), len (), ord (), chr () and print (). If an invalid fone number is entered, then the message "The given fone number is not valid." should be displayed and the user should be asked to enter another number. Sample input/output is as follows (input shown in blue): Enter a fone number or 'nomore' to terminate: 12345678 The fairy's fone number 12345678 is coded as: EFGHIJKL Enter another fone number, 'nomore' to terminate: 09876543 The given fone number is not valid. Enter another fone number, 'nomore' to terminate: 236735 The given fone number is not valid. Enter another fone number, 'nomore' to terminate: 37284332 The fairy's fone number 37284332 is coded as: GKFLHGGF Enter another fone number, 'nomore' to terminate: nomore 2
Step by Step Solution
★★★★★
3.36 Rating (143 Votes )
There are 3 Steps involved in it
Step: 1
Here is the implement...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started