Added code for lecture 2026-11-10
This commit is contained in:
parent
5b630435ae
commit
07b9e54bf0
52 changed files with 1248 additions and 1 deletions
21
lecture20261110/DictionariesAndTry/dictionary2.py
Normal file
21
lecture20261110/DictionariesAndTry/dictionary2.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/python
|
||||
# An office directory example
|
||||
|
||||
dict = {'fName': 'Robert', 'lName': 'Smith', 'Office': 620, 'Phone': '413-755-0000',"Email": "rsmith@example.com"}
|
||||
|
||||
print("dict['fName'] dict['lName']: ", dict['fName']," ", dict['lName'])
|
||||
print ("dict['Office']: ", dict['Office'])
|
||||
print ("dict['Phone']: ", dict['Phone'])
|
||||
|
||||
#Uncomment this next line and the program fails
|
||||
#print ("dict['Mobile']: ", dict['Mobile'])
|
||||
|
||||
try:
|
||||
print("dict['fName'] dict['lName']: ", dict['fName']," ", dict['lName'])
|
||||
print ("dict['Office']: ", dict['Office'])
|
||||
print ("dict['Phone']: ", dict['Phone'])
|
||||
print ("dict['Mobile']: ", dict['Mobile'])
|
||||
except:
|
||||
print("We are in the except block")
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue