Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Python program that reads from the keyboard a word and displays the encr

ID: 3919218 • Letter: W

Question

Write a Python program that reads from the keyboard a word and displays the encrypted version of that word. Assume that only the characters (A, D, I, R, Y ) are allowed in the input word and that the encoding is as shown in the following table:

For example the word RIYAID will be encoded as BATMAN.

You need to use three functions, readWord(), encrypt() and displayEncryption().

readWord() is called by main() to read from the keyboard 6 characters.

• encrypt() is called by main() to convert the characters obtained from readWord() into corresponding encryptions as indicated in the table.

displayEncryption() is called by main() to display the encrypted word on the screen.

Notes:

1. Your program should check the validity of the user input.

Character A D I R Y Encoded M N A B T

Explanation / Answer

I think the code is self explanatory but still i would explain what i have done. For encryption i have created a dictionary which will map every charachter with the associated value.

Before running any function i am checking if the user provided any input or not if no input then i am displaying a message to provide input.

In readWord() function i am using input function to get the input from user keyboard.

In encrypt() function i am first converting the input to upper case so that upper and lower case letters is able to treated properly. I convert the input into a list using list function and then iterate over the list to convert every character to the encrypted one using get method of dictionary. Once the encryption is done i convert it into string using ''.join function.

In displayEncryption() function i am simply displaying the output on screen using print() function.

Also i have taken care of the fact that if there is any word that does not follow encryption my program will print it as is.

Code:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote