2025-1118 Lecture Code
This commit is contained in:
parent
dc82c5032c
commit
34fea7f5da
22 changed files with 450 additions and 0 deletions
BIN
bigos/lecture20251118/ContactScreenshots/0-MainContactScreen.png
Normal file
BIN
bigos/lecture20251118/ContactScreenshots/0-MainContactScreen.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 118 KiB |
BIN
bigos/lecture20251118/ContactScreenshots/1-PhoneDropdown.png
Normal file
BIN
bigos/lecture20251118/ContactScreenshots/1-PhoneDropdown.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 175 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 148 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 172 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 935 KiB |
21
bigos/lecture20251118/dictionaries/dictionary0.py
Normal file
21
bigos/lecture20251118/dictionaries/dictionary0.py
Normal 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. Why?
|
||||
#print(nameDictionary1['age'])
|
||||
21
bigos/lecture20251118/dictionaries/dictionary1.py
Normal file
21
bigos/lecture20251118/dictionaries/dictionary1.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#!/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'])
|
||||
print ("person['Color']: ", person['Color'])
|
||||
print ("person['Phone']: ", person['Phone'])
|
||||
print ("person['Email']: ", person['Email'])
|
||||
|
||||
21
bigos/lecture20251118/dictionaries/dictionary2.py
Normal file
21
bigos/lecture20251118/dictionaries/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")
|
||||
|
||||
|
||||
16
bigos/lecture20251118/dictionaries/dictionary2a.py
Normal file
16
bigos/lecture20251118/dictionaries/dictionary2a.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/python
|
||||
# An office directory example
|
||||
|
||||
dict = {'fName': 'Robert', 'lName': 'Smith', 'Office': 620, 'Phone': '413-755-0000',
|
||||
"Email": "rsmith@example.com"}
|
||||
|
||||
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")
|
||||
print("Does not have a mobile number")
|
||||
|
||||
|
||||
15
bigos/lecture20251118/dictionaries/dictionary3.py
Normal file
15
bigos/lecture20251118/dictionaries/dictionary3.py
Normal 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")
|
||||
14
bigos/lecture20251118/dictionaries/dictionary3a.py
Normal file
14
bigos/lecture20251118/dictionaries/dictionary3a.py
Normal 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")
|
||||
|
||||
26
bigos/lecture20251118/dictionaries/dictionary3b.py
Normal file
26
bigos/lecture20251118/dictionaries/dictionary3b.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/python
|
||||
# A directory example
|
||||
|
||||
dict1 = {'fName': 'Edward', 'lName': 'Bigos', 'Office': 617, 'Phone': '413-755-4544'}
|
||||
|
||||
print("dict1['fName'] dict1['lName']: ", dict1['fName']," ", dict1['lName'])
|
||||
print ("dict1['Office']: ", dict1['Office'])
|
||||
print ("dict1['Phone']: ", dict1['Phone'])
|
||||
|
||||
dict2 = {'fName': 'Edward', 'lName': 'Bigos', 'Office': 617, 'Phone': '413-755-4544'}
|
||||
|
||||
print("dict2['fName'] dict2['lName']: ", dict2['fName']," ", dict2['lName'])
|
||||
print ("dict2['Office']: ", dict2['Office'])
|
||||
print ("dict2['Phone']: ", dict2['Phone'])
|
||||
|
||||
print("Lengths:",len(dict1),len(dict2))
|
||||
print("Types:",type(dict1),type(dict2))
|
||||
|
||||
print(str(dict1)," ", type(str(dict1)))
|
||||
print(str(dict2)," ", type(str(dict2)))
|
||||
|
||||
#print(cmp(dict1,dict2))
|
||||
dict2['Phone'] = "413-000-0000"
|
||||
dict2['Mobile'] = "413-555-0000"
|
||||
dict2['email'] = "none@none.com"
|
||||
print(str(dict2)," ", type(str(dict2)))
|
||||
25
bigos/lecture20251118/dictionaries/dictionary4.py
Normal file
25
bigos/lecture20251118/dictionaries/dictionary4.py
Normal 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'])
|
||||
|
||||
|
||||
|
||||
23
bigos/lecture20251118/dictionaries/weather-data01.py
Normal file
23
bigos/lecture20251118/dictionaries/weather-data01.py
Normal 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)
|
||||
|
||||
39
bigos/lecture20251118/dictionaries/weather-data02.py
Normal file
39
bigos/lecture20251118/dictionaries/weather-data02.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
|
||||
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("\ncoord",weatherData['coord'])
|
||||
print("weather: ",weatherData['weather'])
|
||||
print("base: ",weatherData['base'])
|
||||
print("main: ",weatherData['main'])
|
||||
print("wind: ",weatherData['wind'])
|
||||
print("visibility: ",weatherData['visibility'])
|
||||
print("clouds: ",weatherData['clouds'])
|
||||
print("dt: ",weatherData['dt'])
|
||||
print("sys: ",weatherData['sys'])
|
||||
print("timezone: ",weatherData['timezone'])
|
||||
print("id: ",weatherData['id'])
|
||||
print("name: ",weatherData['name'])
|
||||
print("cod: ",weatherData['cod'])
|
||||
|
||||
43
bigos/lecture20251118/dictionaries/weather-data03.py
Normal file
43
bigos/lecture20251118/dictionaries/weather-data03.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
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("\ncoord",weatherData['coord'])
|
||||
print("weather: ",weatherData['weather'])
|
||||
print("base: ",weatherData['base'])
|
||||
print("main: ",weatherData['main'])
|
||||
print("wind: ",weatherData['wind'])
|
||||
print("visibility: ",weatherData['visibility'])
|
||||
print("clouds: ",weatherData['clouds'])
|
||||
print("dt: ",weatherData['dt'])
|
||||
print("sys: ",weatherData['sys'])
|
||||
print("timezone: ",weatherData['timezone'])
|
||||
print("id: ",weatherData['id'])
|
||||
print("name: ",weatherData['name'])
|
||||
print("cod: ",weatherData['cod'])
|
||||
|
||||
print("\n\n======== Keys ===============")
|
||||
for key in weatherData.keys():
|
||||
print(key)
|
||||
|
||||
51
bigos/lecture20251118/dictionaries/weather-data04.py
Normal file
51
bigos/lecture20251118/dictionaries/weather-data04.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
|
||||
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("\ncoord",weatherData['coord'])
|
||||
print("weather: ",weatherData['weather'])
|
||||
print("base: ",weatherData['base'])
|
||||
print("main: ",weatherData['main'])
|
||||
print("wind: ",weatherData['wind'])
|
||||
print("visibility: ",weatherData['visibility'])
|
||||
print("clouds: ",weatherData['clouds'])
|
||||
print("dt: ",weatherData['dt'])
|
||||
print("sys: ",weatherData['sys'])
|
||||
print("timezone: ",weatherData['timezone'])
|
||||
print("id: ",weatherData['id'])
|
||||
print("name: ",weatherData['name'])
|
||||
print("cod: ",weatherData['cod'])
|
||||
|
||||
print("\n\n======== Keys ===============")
|
||||
for key in weatherData.keys():
|
||||
print(f" {key:12} {weatherData[key]} ")
|
||||
|
||||
kelvinTemp = weatherData['main']['temp']
|
||||
fahr = (kelvinTemp - 273.15) * 9/5 + 32
|
||||
print(f"Fahrenheit temp is {fahr:.1f} degrees")
|
||||
|
||||
pressure = weatherData['main']['pressure'] * 0.0145038
|
||||
print(weatherData['main']['pressure'])
|
||||
print(f"The pressure is {pressure:.1f} psi")
|
||||
|
||||
print(weatherData['name'],weatherData['sys']['country'])
|
||||
55
bigos/lecture20251118/dictionaries/weather-data07.py
Normal file
55
bigos/lecture20251118/dictionaries/weather-data07.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
|
||||
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("\ncoord",weatherData['coord'])
|
||||
print("weather: ",weatherData['weather'])
|
||||
print("base: ",weatherData['base'])
|
||||
print("main: ",weatherData['main'])
|
||||
print("wind: ",weatherData['wind'])
|
||||
print("visibility: ",weatherData['visibility'])
|
||||
print("clouds: ",weatherData['clouds'])
|
||||
print("dt: ",weatherData['dt'])
|
||||
print("sys: ",weatherData['sys'])
|
||||
print("timezone: ",weatherData['timezone'])
|
||||
print("id: ",weatherData['id'])
|
||||
print("name: ",weatherData['name'])
|
||||
print("cod: ",weatherData['cod'])
|
||||
|
||||
print("Keys")
|
||||
for key in weatherData.keys():
|
||||
print(key)
|
||||
|
||||
print("Keys and Data")
|
||||
for key in weatherData.keys():
|
||||
print(f"{key:10s}: {weatherData[key]}")
|
||||
|
||||
# Accessing Latitude and Longitude
|
||||
print(f"Latitude,Longitude = {weatherData['coord']['lat']},{weatherData['coord']['lon']}")
|
||||
|
||||
# Accessing Latitude and Longitude (Alternate method)
|
||||
# Assign the coord dictionary to a new variable. Now use the new variable to manipulate the data.
|
||||
coordinates = weatherData['coord']
|
||||
print(f"Latitude,Longitude = {coordinates['lat']},{coordinates['lon']}")
|
||||
|
||||
6
bigos/lecture20251118/secrets/secrets1.py
Executable file
6
bigos/lecture20251118/secrets/secrets1.py
Executable file
|
|
@ -0,0 +1,6 @@
|
|||
secrets = {
|
||||
'location': 'stcc',
|
||||
'ssid': 'cset@stcc',
|
||||
'password': 'c1s2e3t4',
|
||||
}
|
||||
|
||||
29
bigos/lecture20251118/secrets/secrets2.py
Executable file
29
bigos/lecture20251118/secrets/secrets2.py
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
secrets = {
|
||||
'location': 'stcc',
|
||||
'ssid': 'cset@stcc',
|
||||
'password': 'c1s2e3t4',
|
||||
}
|
||||
|
||||
SSIDsecrets = {
|
||||
'stcc': {
|
||||
'ssid': 'cset@stcc',
|
||||
'password': 'c1s2e3t4'
|
||||
},
|
||||
'chicopee': {
|
||||
'ssid': 'firefly',
|
||||
'password': 'c1s2e3t4'
|
||||
},
|
||||
'worthington': {
|
||||
'ssid': 'serenity',
|
||||
'password': 'c1s2e3t4'
|
||||
},
|
||||
'badssid': {
|
||||
'ssid': 'spaceX',
|
||||
'password': 'c1s2e3t4'
|
||||
},
|
||||
'badpassword': {
|
||||
'ssid': 'cset@stcc',
|
||||
'password': '9988776655'
|
||||
}
|
||||
}
|
||||
|
||||
17
bigos/lecture20251118/secrets/test_secrets1.py
Executable file
17
bigos/lecture20251118/secrets/test_secrets1.py
Executable file
|
|
@ -0,0 +1,17 @@
|
|||
from secrets1 import secrets
|
||||
|
||||
|
||||
# Load login data from different file for safety reasons
|
||||
WiFiLocation = secrets['location']
|
||||
WiFiSSID = secrets['ssid']
|
||||
WiFiPassword = secrets['password']
|
||||
|
||||
print(WiFiLocation)
|
||||
print(WiFiSSID)
|
||||
print(WiFiPassword)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
28
bigos/lecture20251118/secrets/test_secrets2.py
Executable file
28
bigos/lecture20251118/secrets/test_secrets2.py
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
from secrets2 import secrets
|
||||
from secrets2 import SSIDsecrets
|
||||
|
||||
# Load login data from different file for safety reasons
|
||||
WiFiLocation = secrets['location']
|
||||
WiFiSSID = secrets['ssid']
|
||||
WiFiPassword = secrets['password']
|
||||
|
||||
print(WiFiLocation)
|
||||
print(WiFiSSID)
|
||||
print(WiFiPassword)
|
||||
|
||||
locations = ['stcc', 'chicopee','worthington','badssid', 'badpassword']
|
||||
|
||||
for location in locations:
|
||||
# Load login data from different file for safety reasons
|
||||
print(f"\n Location = {location}\n")
|
||||
WiFiLocation = SSIDsecrets[location]
|
||||
WiFiSSID = SSIDsecrets[location]['ssid']
|
||||
WiFiPassword = SSIDsecrets[location]['password']
|
||||
|
||||
print(WiFiLocation)
|
||||
print(WiFiSSID)
|
||||
print(WiFiPassword)
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue