+1 (315) 557-6473 

Work With Dictionaries in The Python Assignment Solution.


Instructions

Objective
Write a python assignment to work with dictionaries.

Requirements and Specifications

Introduction:
Assignments evaluates understanding student understanding of dictionaries.
Instructions:
  1. Create a Python code file named M4Lab_Encryption_FirstLast.py
  2. (replace "FirstLast" with your own name)

  3.  Add a title comment block to the top of the new Python file using the following form
  4. # A brief description of the project

    # Date

    # CSC-121-Encryption

    # Your Name

  5. Create a program that uses a dictionary to assign "codes" to each character in the alphabet. For example
  6. codes = {'A' : ')' , 'a' : '0' , 'B' : '(' , 'b' : '9' ,.......}

  7. Using the example above, the letter 'A' would be converted to a parentheses ')' and the letter 'a' would be converted to a zero (0) and so on.
  8. The program is to ask the user to enter a sentence, then pass the sentence to a function that would create an encrypted version of the sentence.
  9. The function that evalutes the sentence is to use a loop to iterate over the sentence then use the dictionary and create the encrypted version of the sentence. This function is a value returning function, meaning it is to return the encrypted version of the sentence.
  10. The program is to then display the encrypted version of the sentence

Source Code

# A brief description of the project

# Date

# CSC-121-Encryption

# Your Name

codes = {'A': ')', 'B': '(', 'C': '*', 'D': '&', 'E': '^', 'F': '%', 'G': '$', 'H': '#', 'I': '@', 'J': '!',

         'K': '}', 'L': '{', 'M': 'P', 'N': 'O', 'O': 'I', 'P': 'U', 'Q': 'Y', 'R': 'T', 'S': 'R', 'T': 'E',

         'U': 'W', 'V': 'Q', 'W': '"', 'X': ':', 'Y': 'L', 'Z': 'K',

         'a': '0', 'b': '9', 'c': '8', 'd': '7', 'e': '6', 'f': '5', 'g': '4', 'h': '3', 'i': '2', 'j': '1',

         'k': ']', 'l': '[', 'm': 'p', 'n': 'o', 'o': 'i', 'p': 'u', 'q': 'y', 'r': 't', 's': 'r', 't': 'e',

         'u': 'w', 'v': 'q', 'w': '\'', 'x': ';', 'y': 'l', 'z': 'k'}

def encode(text):

    result = ""

    for c in text:

        if c in codes:

            result += codes[c]

        else:

            result += c

    return result

plain_text = input('Please, enter the sentence: ')

encrypted = encode(plain_text)

print('Encrypted sentence:', encrypted)