Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python question using thonny wure TUUS Help Thonny - /Users/albertouaknine/Downloads/encryption.py encryption.py 1 # Author: [your name here] 2 # McGill ID: [your ID here] 3

python question using thonny image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
wure TUUS Help Thonny - /Users/albertouaknine/Downloads/encryption.py encryption.py 1 # Author: [your name here] 2 # McGill ID: [your ID here] 3 # Assignment 1, Question 3 5 import random # Given a dictionary d and value V, 8 # find and return the key associated with that value. 9 # (From the slides.) 10 def reverse_lookup(d, v): for key in d: if d[keyl - v: return key return None LETTERS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPORSTUVWXYZ1234567890!#$%^&*()'-_+00 def create cypher dictionary(): random seed (1337) # important - please keep this line here. cypher - 0 Create empty dictionary ':"../0? # add code here return cypher return the completed cypher dictionary def encrypt(s): cypher - create_cypher_dictionary() get the cypher dictionary Shell Python 3.7.5 (bundled) | H Mi D Thonny - /Users/albertoakning/Downloads/encryption by Sat 73 56: 64 encryption.py det encrypt(s): cypher = create_cypher dictionary() # get the cypher dictionary # add your code here def decrypt(s): cypher - create_cypher_dictionary() # get the Cypher dictionary add your code here def encrypt_multiple times (s, n): pass # delete this line and add your code here 39 Source: https://en.wikipedia.org/wiki/Most common word 40 COMMON_WORDS - "the", "be","to", of , and in English that have", "1", "it", " for ","not", "on 42 def decrypt multiple times(s): cypher = create cypher dictionary get the add your code here s = input ("Enter text to encrypt:) # add your code here * 50% Sat 7:35 PM Thonny - Users/albertoaknine Downloads/encryption.py 56.64 Assistant tionary pher dictionary wpher dictionary words in English nd","a", " in ", " that "," have", "I", "it", "for ","not", "on", "with ","he","as", "you","do","at" pher dictionary M wevice Tools Help Thonny /Users/albertouraknine/Downloads/eng encryption.py 30 i elrypLID) 31 cypher - create_cypher_dictionary() # get the cypher dictionary # add your code here def encrypt_multiple_times (s, n): pass # delete this line and add your code here # Source: https://en.wikipedia.org/wiki/Most common words_in_English COMMON WORDS = " the ", " be ", " to ", " of "," and ","a", " in "," that ", " have ", " def decrypt_multiple_times (s): cypher = create_cypher_dictionary() # get the cypher dictionary # add your code here 47 s = input("Enter text to encrypt: ") 49 # add your code here 50 51 print("Encrypted string:", encrypt(s)) 52 print("Decrypted string:", decrypt (encrypt(s))) 53 54 salted_s = encrypt_multiple_times(s, 2) 55 print("Encrypted x2 string:", salted_s) 56 print("Decrypted x2 string:", decrypt_multiple_times(salted_s)) Question 1 (15 points) This question will ask you to do an exercise involving lists. You are asked to write a function fetch that takes in a list of positive, non-zero integers, and returns the smallest integer not in the list. For example, the smallest positive integer not in the list [1, 5, 2) is 3, so the function should return 3. You must also write a function get input from user that creates a list based on user input, which we will use to create the list for the first function. The two functions should be implemented as follows: Name: fetch Parameters: A list 'numbers' of positive, non-zero integer values. Return value: The smallest positive integer not in the list. If an empty list is given, return the value 1. Name: get list from input Parameters: No parameters Return value: A list of positive, non-zero integers entered by the user. What it should do: Ask the user to enter a number(s) with the prompt 'Enter number(s): then convert their entered numbers to integer and store them in a list. Keep asking the user to enter numbers until they enter the word 'done', at which point you should return the list of all numbers entered. The user may enter just one number on a line, or they could enter a series of comma-separated numbers, in which case each of the numbers must be added to the list. If the user enters any values less than 1, do not add them to the list. For example, if the user enters "4,5,-2" on one line, 4 and 5 should be added to the list, but-2 should not. You can assume the user will not enter any spaces, and only enter digits from 0-9 without any letters or special characters. Filename ols Window Help % 50% Sat 7:35 PM COMP 208 Winter_2020 Assignment 2 rev3.pdf (page 3 of 12) Search Filename You must write this program in a file called sequence.py. In the file, the two functions are already defined for you, and at the bottom of the file there are calls to the functions. Examples (as executed in Thonny) EXAMPLE 1: >>> %Run sequence.py Enter number(s): done EXAMPLE 2: Enter number(s): 0 Enter number(s): done EXAMPLE 2: >>> %Run sequence.py Enter number(s): 0 Enter number(s): done EXAMPLE 3: >>> %Run sequence.py Enter number(s): 1 Enter number(s): done EXAMPLE 4: >>> %Run sequence: py Enter number(s): 1 Enter number(s): 5 Enter number(s): 2 Enter number(s): done EXAMPLE 5: >>> Run Enter number (s): 1 Enter number(s): 2 Enter number(s): 3 Enter number(s): 4 Enter number(s): done Tools Window Help COMP 208 Winter 2020 Assignment_2_rev3.pdf (page 4 of 12) Enter number(s): 4 Enter number(s): done EXAMPLE 6: >>> %Run sequence.py Enter number(s): 1,5,2 Enter number(s): 3,7,6 Enter number(s): 4,8 Enter number(s): done

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions