Question
Sourse code: names = { Euclid :10, Archimedes :20, Newton :30, Descartes :40, Fermat :40, Turing :60, Euler :70, Einstein :80, Boole :90, Fibonacci :100,
Sourse code: names = { "Euclid":10, "Archimedes":20, "Newton":30, "Descartes":40, "Fermat":40, "Turing":60, "Euler":70, "Einstein":80, "Boole":90, "Fibonacci":100, "Nash":110, } print("1 ",names.keys()) # print keys print("2 ", names.values() ) for key in names: print('22...',names[key]) #use in to search for keys as well as non-existance keys if "Euler" in names: print("3 ", names["Euler"]) else: print("error 1") if "cat" in names: print("4 ",names["cat"]) else: print("error 2") # we can also use the not operator as in # if "cat" not in names: a = set('abracadabra') b = set('alacazam') print('5 ',a) # unique letters in a # OUTPUT == ['a', 'r', 'b', 'c', 'd'] print('6 ',a - b) # letters in a but not in b # OUTPUT == ['r', 'd', 'b'] print( '7', a | b) # letters in either a or b # OUTPUT == {'a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'] print( '8 ', a & b) # letters in both a and b # OUTPUT == ['a', 'c']) print( '9 ',a ^ b) # letters in a or b but not both # OUTPUT == ['r', 'd', 'b', 'm', 'z', 'l'] # converting a list to a set a = [11, 22, 33, 44, "Euler"] s = set(a) print('10 ', s)
Write a python program that asks
a.The user for a string andcreate the following dictionary: The values are the letters in the string, with the corresponding key being the place in the string. For example if the user entered the string CSC120 then create the dictionary d
d = {'C':0, 'S':1, 'C':2, '1':3, '2':4, '0':5}
b.Ask the user for a string of digits, and then print out the values corresponding to those digits. For example if the user enters 014 then print out C S 2 (or CS2 ) See the Lab09Template.py code for a suggested approach to responding to incorrect digits for example any digits 05 should generate a corresponding value but any digit(s) > 5 has to handledwithout generating an error
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started