×
Samples Blogs Make Payment About Us 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
Use Python libraries effectively by importing only what you need. For example, if you're working with data, using libraries like pandas and numpy can save time and simplify complex tasks like data manipulation and analysis.
News
In 2024, the Biden-Harris Administration has expanded high-dosage tutoring and extended learning programs to boost academic achievement, helping programming students and others recover from pandemic-related setbacks. These initiatives are funded by federal resources aimed at improving math and literacy skills​

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.