×
Reviews 4.9/5 Order Now

Work With Dictionaries in The Python Assignment Solution

July 02, 2024
Isaac Connolly
Isaac Connolly
🇨🇦 Canada
Python
Isaac Connolly is an adept Python Assignment Expert with 12 years of experience, holding a prestigious Master's degree from a leading institution in Canada.
Key Topics
  • Instructions
  • Requirements and Specifications
Tip of the day
When working on Ajax assignments, always validate server responses to handle errors effectively. Use tools like browser developer consoles to debug requests and ensure asynchronous calls are optimized for better performance and user experience.
News
SolidJS Known for its fine-grained reactivity and direct DOM updates, leading to significant performance improvements in real-time data applications.

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)

Related Samples

Explore our Python Assignment Samples for comprehensive solutions to coding challenges. These examples cover essential topics such as loops, functions, data structures, and algorithmic problems. Perfect for students seeking practical insights to excel in Python programming assignments and deepen their coding proficiency effectively.