Started Rectangle Project

This commit is contained in:
cmitchell2301 2025-12-14 18:34:36 -05:00
commit 26e1253c0d
39 changed files with 544 additions and 0 deletions

View file

@ -0,0 +1,21 @@
nameList = ["John", "Smith"]
nameDictionary = {'firstName': "John", 'lastName': "Smith", 'age': 24}
nameDictionary1 = {'firstName': "Mary", 'lastName': "Smith"}
namesList = [nameDictionary,nameDictionary1]
print(nameList)
print(nameDictionary)
print(namesList)
print(nameDictionary['firstName'])
print(nameDictionary['lastName'])
print(nameDictionary['age'])
print(nameDictionary1['firstName'])
print(nameDictionary1['lastName'])
# Uncomment this and it generates an error
#print(nameDictionary1['age'])

View file

@ -0,0 +1,17 @@
#!/usr/bin/python
#Tutorialspoint
# https://www.tutorialspoint.com/python/python_dictionary.htm
# Accessing Values in Dictionary
import pprint
person = {'Name': 'Zara', 'Age': 7, 'Class': 'First','Color':'Green','Phone': "413-781-7822",'Email': "bgates@microsoft.com"}
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(person)
print("\n")
print("person['Name']: ", person['Name'])
print ("person['Age']: ", person['Age'])

View 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")

View file

@ -0,0 +1,15 @@
#!/usr/bin/python
# A directory example
dict = {'fName': 'Edward', 'lName': 'Bigos', 'Office': 617, 'Phone': '413-755-4544'}
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 KeyError:
print("\nInvalid key selected.")
print("Sorry, there is no mobile phone number in the directory.")
print("\n")

View file

@ -0,0 +1,14 @@
#!/usr/bin/python
# A directory example
dict = {'fName': 'Edward', 'lName': 'Bigos', 'Office': 617, 'Phone': '413-755-4544'}
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 KeyError:
print("Invalid key selected.")
print("Sorry, there is no key with that name in the directory.")
print("\n")

View file

@ -0,0 +1,25 @@
#!/usr/bin/python
# Create three dictionaries
dict1 = {'fName': 'Edward', 'lName': 'Bigos', 'Office': 617, 'Phone': '413-755-4544'}
dict2 = {'fName': 'Bill', 'lName': 'Gates', 'Office': 700, }
dict3 = {'fName': 'Harry', 'lName': 'Smith', 'Office': 677, 'Phone': '413-000-0000'}
# Put the three dictionaries in a list
staff = [dict1,dict2, dict3]
print(staff)
print("\n")
print("=============================\n\t\tDirectory\n=============================")
for person in staff:
# Person is a dictionary. Uncomment the next line to print the type.
#print(person, type(person))
try:
print(person['lName'], person['fName'], person['Phone'])
except:
print(person['lName'], person['fName'])

View file

@ -0,0 +1,23 @@
import pprint
weatherData = {'coord': {'lon': -72.5949, 'lat': 42.1726},
'weather': [{'id': 801, 'main': 'Clouds', 'description': 'few clouds', 'icon': '02n'}],
'base': 'stations',
'main': {'temp': 285.11, 'feels_like': 283.25, 'temp_min': 282.18, 'temp_max': 286.21,
'pressure': 1015, 'humidity': 34},
'visibility': 10000,
'wind': {'speed': 3.6, 'deg': 160},
'clouds': {'all': 20},
'dt': 1649723543,
'sys': {'type': 1, 'id': 3598, 'country': 'US', 'sunrise': 1649672158,
'sunset': 1649719584},
'timezone': -14400,
'id': 4933002,
'name': 'Chicopee',
'cod': 200}
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(weatherData)

View file

@ -0,0 +1,31 @@
import pprint
weatherData = {'coord': {'lon': -72.5949, 'lat': 42.1726},
'weather': [{'id': 801, 'main': 'Clouds', 'description': 'few clouds', 'icon': '02n'}],
'base': 'stations',
'main': {'temp': 285.11, 'feels_like': 283.25, 'temp_min': 282.18, 'temp_max': 286.21,
'pressure': 1015, 'humidity': 34},
'visibility': 10000,
'wind': {'speed': 3.6, 'deg': 160},
'clouds': {'all': 20},
'dt': 1649723543,
'sys': {'type': 1, 'id': 3598, 'country': 'US', 'sunrise': 1649672158,
'sunset': 1649719584},
'timezone': -14400,
'id': 4933002,
'name': 'Chicopee',
'cod': 200}
#pp = pprint.PrettyPrinter(indent=4)
#pp.pprint(weatherData)
#print("\n")
print("coord",weatherData['coord'])
print("weather: ",weatherData['weather'])
print("base: ",weatherData['base'])
print("main: ",weatherData['main'])
print("wind: ",weatherData['wind'])

View file

@ -0,0 +1,24 @@
import pprint
weatherData = {'coord': {'lon': -72.5949, 'lat': 42.1726},
'weather': [{'id': 801, 'main': 'Clouds', 'description': 'few clouds', 'icon': '02n'}],
'base': 'stations',
'main': {'temp': 285.11, 'feels_like': 283.25, 'temp_min': 282.18, 'temp_max': 286.21,
'pressure': 1015, 'humidity': 34},
'visibility': 10000,
'wind': {'speed': 3.6, 'deg': 160},
'clouds': {'all': 20},
'dt': 1649723543,
'sys': {'type': 1, 'id': 3598, 'country': 'US', 'sunrise': 1649672158,
'sunset': 1649719584},
'timezone': -14400,
'id': 4933002,
'name': 'Chicopee',
'cod': 200}
print("\n\n======== Keys ===============")
for key in weatherData.keys():
print(key)

View file

@ -0,0 +1,25 @@
import pprint
weatherData = {'coord': {'lon': -72.5949, 'lat': 42.1726},
'weather': [{'id': 801, 'main': 'Clouds', 'description': 'few clouds', 'icon': '02n'}],
'base': 'stations',
'main': {'temp': 285.11, 'feels_like': 283.25, 'temp_min': 282.18, 'temp_max': 286.21,
'pressure': 1015, 'humidity': 34},
'visibility': 10000,
'wind': {'speed': 3.6, 'deg': 160},
'clouds': {'all': 20},
'dt': 1649723543,
'sys': {'type': 1, 'id': 3598, 'country': 'US', 'sunrise': 1649672158,
'sunset': 1649719584},
'timezone': -14400,
'id': 4933002,
'name': 'Chicopee',
'cod': 200}
print("\n\n======== Keys and Data ===============")
for key in weatherData.keys():
print(f" {key:12} {weatherData[key]} ")