Create a new python file called pirates.py
and save to your cs100/ch4
folder.
cents = { 'Nickel': 5, 'Dime': 10, 'Quarter': 25, 'Dollar': 100}
For example, iterate through the dictionary by key and print out all key/value pairs. Next, use the keys()
function to obtain all keys from your dictionary and then print it out to test it. Make sure you are printing the results of the function calls / operations used on your dictionary to test how it works.
personnel = {'Joe': 2000, 'Ana': 2500, 'Bob': 1800, 'Chris': 2100, 'Diana': 1900}
toPirate(sentence)
, that takes an English sentence in the form of a string as a parameter. The toPirate
function should return a string containing the pirate translation of your sentence. Use the table below to construct a translation dictionary. You can also consult other sources online for more pirate phrases.English | Pirate Translation | |
---|---|---|
Greetings | hello excuse |
avast arr |
People | sir, boy, man madam officer |
matey proud beauty foul blaggart |
Articles | the my your is are |
th' me yer be be |
Places | restroom restaurant hotel |
head galley fleabag inn |
Test your function with a few different inputs. For example:
sentence = "hello there madam how are you"
print( toPirate(sentence) ) # will print "avast there proud beauty how be you"
Write Python code (no function need) to create a dictionary named userPasswords
which holds 3 usernames (as keys) and their corresponding passwords (as values). Your program should allow for the user to input these values. Use a loop to ask the user for input for the username and for the password. Print the dictionary after all username/passwords have been added.
Add code that asks the user to input their username. Your program will print their password, or “User not found” if the username doesn’t exist. This simulates that a user forgot their password.
Add code that asks the user to input their username and then their password. Check if the passwords match.
Challenging: Create a new dictionary called protectedUserPasswords
which asks the user to type in 3 username/password pairs.This time, store the password as encrypted text rather than plain text. Next, add code so that the user can input their username/password and check for a match. Hint: think about how to match a password to an encrypted password.
Write a function combineDictionaries(d1, d2)
that takes two dictionaries as parameters and returns a new dictionary that includes the items from both.
Test your function with:
nhl1 = {
"Toronto": "Maple Leafs",
"Montreal": "Canadiens",
"Vancouver": "Canucks",
"Boston": "Bruins",
"Edmonton": "Oilers",
"New York": "Rangers"
}
nhl2 = {
"Detroit": "Red Wings",
"Pittsburgh": "Penguins",
"Philedelphia": "Flyers",
"Calgary": "Flames",
"Tampa Bay": "Lightning"
}
print( combineDictionaries(nhl1, nhl2) )
Submit your working python file to Moodle.