added code to 11/5
parent
82daf9b933
commit
96c3dc84e3
|
@ -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'])
|
|
@ -0,0 +1,20 @@
|
||||||
|
#!/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'])
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
|
||||||
|
|
||||||
|
names = ["Tanner", "Gimli", "Mandy", "Jack"]
|
||||||
|
ages = [16, 2, 8, 4]
|
||||||
|
|
||||||
|
print(names)
|
||||||
|
|
||||||
|
for x in names:
|
||||||
|
print(x)
|
||||||
|
for x in ages:
|
||||||
|
print(x)
|
||||||
|
|
||||||
|
print("done")
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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']}")
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
|
||||||
|
def averageValue(data1,data2,data3):
|
||||||
|
averageValue = (data1 + data2 + data3)/3
|
||||||
|
return averageValue
|
||||||
|
|
||||||
|
data1 = 12
|
||||||
|
data2 = 2
|
||||||
|
data3 = 5
|
||||||
|
|
||||||
|
# Calculate the average
|
||||||
|
|
||||||
|
averageData = (data1 + data2 + data3)/3
|
||||||
|
|
||||||
|
print(f"The average is {averageData:.2f}")
|
||||||
|
|
||||||
|
averageData = averageValue(data1,data2,data3)
|
||||||
|
|
||||||
|
print(f"The average is {averageData:.2f}")
|
|
@ -0,0 +1,70 @@
|
||||||
|
# Program scores1.py
|
||||||
|
# ============================================================
|
||||||
|
def is_float(s):
|
||||||
|
""" Returns True if string is a number. """
|
||||||
|
try:
|
||||||
|
float(s)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def is_int(s):
|
||||||
|
""" Returns True if string is a number. """
|
||||||
|
try:
|
||||||
|
int(s)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def getinteger(Message):
|
||||||
|
myInteger =input(Message)
|
||||||
|
if is_int(myInteger):
|
||||||
|
width = int(myInteger)
|
||||||
|
else:
|
||||||
|
print("This was not an int.")
|
||||||
|
print("Program Terminates in getInteger.")
|
||||||
|
exit(-1)
|
||||||
|
return myInteger
|
||||||
|
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def getfloat(Message):
|
||||||
|
myFloat =input(Message)
|
||||||
|
if is_float(myFloat):
|
||||||
|
myFloat = float(myFloat)
|
||||||
|
else:
|
||||||
|
print("This was not an float.")
|
||||||
|
print("Program Terminates in getFloat.")
|
||||||
|
exit(-1)
|
||||||
|
return myFloat
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def getScores(numberOfScores):
|
||||||
|
counter = 0
|
||||||
|
scores = []
|
||||||
|
while(counter < numberOfScores):
|
||||||
|
myScore = getfloat("Enter the next exam score ")
|
||||||
|
# print(type(myScore))
|
||||||
|
scores.append(myScore)
|
||||||
|
print(counter,scores)
|
||||||
|
counter = counter + 1
|
||||||
|
|
||||||
|
return scores
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def getScoreAverage(scores):
|
||||||
|
sumOfScores = 0
|
||||||
|
for dummy in scores:
|
||||||
|
sumOfScores = sumOfScores + dummy
|
||||||
|
|
||||||
|
averageScore = sumOfScores/len(scores)
|
||||||
|
return averageScore
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
# Test getIneger
|
||||||
|
|
||||||
|
someInteger = getinteger("Enter a value for the length ")
|
||||||
|
print(f"The value is {someInteger}")
|
||||||
|
|
||||||
|
someInteger = input("Enter a value for the length ")
|
||||||
|
someInteger = int(someInteger)
|
||||||
|
print(f"The value is {someInteger}")
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
# Program scores3.py
|
||||||
|
# ============================================================
|
||||||
|
def is_float(s):
|
||||||
|
""" Returns True if string is a number. """
|
||||||
|
try:
|
||||||
|
float(s)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def is_int(s):
|
||||||
|
""" Returns True if string is a number. """
|
||||||
|
try:
|
||||||
|
int(s)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def getinteger(Message):
|
||||||
|
myInteger =input(Message)
|
||||||
|
if is_int(myInteger):
|
||||||
|
width = int(myInteger)
|
||||||
|
else:
|
||||||
|
print("This was not an int.")
|
||||||
|
print("Program Terminates in getInteger.")
|
||||||
|
exit(-1)
|
||||||
|
return myInteger
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def getfloat(Message):
|
||||||
|
myFloat =input(Message)
|
||||||
|
if is_float(myFloat):
|
||||||
|
myFloat = float(myFloat)
|
||||||
|
else:
|
||||||
|
print("This was not an float.")
|
||||||
|
print("Program Terminates in getFloat.")
|
||||||
|
exit(-1)
|
||||||
|
return myFloat
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def getScores(numberOfScores):
|
||||||
|
counter = 0
|
||||||
|
scores = []
|
||||||
|
while(counter < numberOfScores):
|
||||||
|
myScore = getfloat("Enter the next exam score ")
|
||||||
|
# print(type(myScore))
|
||||||
|
scores.append(myScore)
|
||||||
|
print(counter,scores)
|
||||||
|
counter = counter + 1
|
||||||
|
return scores
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def getScoreAverage(scores):
|
||||||
|
sumOfScores = 0
|
||||||
|
for dummy in scores:
|
||||||
|
sumOfScores = sumOfScores + dummy
|
||||||
|
|
||||||
|
averageScore = sumOfScores/len(scores)
|
||||||
|
return averageScore
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
# List of class members.
|
||||||
|
classList = [{'name': 'Harry', 'scores': [98, 87, 92, 96, 100]},
|
||||||
|
{'name': 'Alice', 'scores': [89, 97, 100, 96, 100]},
|
||||||
|
{'name': 'Mandy', 'scores': [99, 93, 100, 100, 100]},
|
||||||
|
{'name': 'Rusty', 'scores': [99, 100, 100, 92, 100]},
|
||||||
|
{ 'scores': [99, 100, 100, 92, 100], 'name': 'Katrina', 'phoneNumber': "413-781-7822"},
|
||||||
|
]
|
||||||
|
|
||||||
|
for eachElement in classList:
|
||||||
|
print(eachElement)
|
||||||
|
print(eachElement['name'])
|
||||||
|
print(eachElement['scores'])
|
||||||
|
|
||||||
|
averageScore = getScoreAverage(classList[0]['scores'])
|
||||||
|
print(f"Average Score for {classList[0]['name']} is {averageScore:.2f}")
|
||||||
|
|
||||||
|
for eachElement in classList:
|
||||||
|
averageScore = getScoreAverage(eachElement['scores'])
|
||||||
|
print(f"Average Score for {eachElement['name']} is {averageScore:.2f}")
|
|
@ -0,0 +1,66 @@
|
||||||
|
/usr/local/bin/python3.11 /Users/edbigos/PycharmProjects/assignment04demo/iss1.py
|
||||||
|
{'people': [{'craft': 'Tiangong', 'name': 'Jing Haiping'}, {'craft': 'Tiangong', 'name': 'Gui Haichow'}, {'craft': 'Tiangong', 'name': 'Zhu Yangzhu'}, {'craft': 'ISS', 'name': 'Jasmin Moghbeli'}, {'craft': 'ISS', 'name': 'Andreas Mogensen'}, {'craft': 'ISS', 'name': 'Satoshi Furukawa'}, {'craft': 'ISS', 'name': 'Konstantin Borisov'}, {'craft': 'ISS', 'name': 'Oleg Kononenko'}, {'craft': 'ISS', 'name': 'Nikolai Chub'}, {'craft': 'ISS', 'name': "Loral O'Hara"}], 'number': 10, 'message': 'success'}
|
||||||
|
|
||||||
|
jsonPeople
|
||||||
|
{
|
||||||
|
"people": [
|
||||||
|
{
|
||||||
|
"craft": "Tiangong",
|
||||||
|
"name": "Jing Haiping"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"craft": "Tiangong",
|
||||||
|
"name": "Gui Haichow"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"craft": "Tiangong",
|
||||||
|
"name": "Zhu Yangzhu"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"craft": "ISS",
|
||||||
|
"name": "Jasmin Moghbeli"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"craft": "ISS",
|
||||||
|
"name": "Andreas Mogensen"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"craft": "ISS",
|
||||||
|
"name": "Satoshi Furukawa"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"craft": "ISS",
|
||||||
|
"name": "Konstantin Borisov"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"craft": "ISS",
|
||||||
|
"name": "Oleg Kononenko"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"craft": "ISS",
|
||||||
|
"name": "Nikolai Chub"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"craft": "ISS",
|
||||||
|
"name": "Loral O'Hara"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"number": 10,
|
||||||
|
"message": "success"
|
||||||
|
}
|
||||||
|
People on the ISS: 10
|
||||||
|
Jing Haiping
|
||||||
|
Gui Haichow
|
||||||
|
Zhu Yangzhu
|
||||||
|
Jasmin Moghbeli
|
||||||
|
Andreas Mogensen
|
||||||
|
Satoshi Furukawa
|
||||||
|
Konstantin Borisov
|
||||||
|
Oleg Kononenko
|
||||||
|
Nikolai Chub
|
||||||
|
Loral O'Hara
|
||||||
|
{'timestamp': 1698153985, 'message': 'success', 'iss_position': {'latitude': '0.5392', 'longitude': '-7.0103'}}
|
||||||
|
Latitude: 0.5392
|
||||||
|
Longitude: -7.0103
|
||||||
|
|
||||||
|
Process finished with exit code 0
|
|
@ -0,0 +1,41 @@
|
||||||
|
|
||||||
|
import json
|
||||||
|
import urllib.request
|
||||||
|
import turtle
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
url = 'http://api.open-notify.org/astros.json'
|
||||||
|
response = urllib.request.urlopen(url)
|
||||||
|
result = json.loads(response.read())
|
||||||
|
|
||||||
|
print(result)
|
||||||
|
|
||||||
|
jsonPeople = json.dumps(result,indent=4 )
|
||||||
|
print("\njsonPeople")
|
||||||
|
print(jsonPeople)
|
||||||
|
|
||||||
|
|
||||||
|
print("People on the ISS: ",result['number'])
|
||||||
|
people = result['people']
|
||||||
|
#print(people)
|
||||||
|
|
||||||
|
#for person in people:
|
||||||
|
# print(person)
|
||||||
|
|
||||||
|
for person in people :
|
||||||
|
print(person['name'])
|
||||||
|
|
||||||
|
|
||||||
|
url = 'http://api.open-notify.org/iss-now.json'
|
||||||
|
response = urllib.request.urlopen(url)
|
||||||
|
result = json.loads(response.read())
|
||||||
|
|
||||||
|
print(result)
|
||||||
|
|
||||||
|
location = result['iss_position']
|
||||||
|
latitude = location['latitude']
|
||||||
|
longitude = location['longitude']
|
||||||
|
|
||||||
|
print('Latitude: ',latitude)
|
||||||
|
print('Longitude: ',longitude)
|
|
@ -0,0 +1,69 @@
|
||||||
|
# Program scores1.py
|
||||||
|
# ============================================================
|
||||||
|
def is_float(s):
|
||||||
|
""" Returns True if string is a number. """
|
||||||
|
try:
|
||||||
|
float(s)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def is_int(s):
|
||||||
|
""" Returns True if string is a number. """
|
||||||
|
try:
|
||||||
|
int(s)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def getinteger(Message):
|
||||||
|
myInteger =input(Message)
|
||||||
|
if is_int(myInteger):
|
||||||
|
width = int(myInteger)
|
||||||
|
else:
|
||||||
|
print("This was not an int.")
|
||||||
|
print("Program Terminates in getInteger.")
|
||||||
|
exit(-1)
|
||||||
|
return myInteger
|
||||||
|
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def getfloat(Message):
|
||||||
|
myFloat =input(Message)
|
||||||
|
if is_float(myFloat):
|
||||||
|
myFloat = float(myFloat)
|
||||||
|
else:
|
||||||
|
print("This was not an float.")
|
||||||
|
print("Program Terminates in getFloat.")
|
||||||
|
exit(-1)
|
||||||
|
return myFloat
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def getScores(numberOfScores):
|
||||||
|
counter = 0
|
||||||
|
scores = []
|
||||||
|
while(counter < numberOfScores):
|
||||||
|
myScore = getfloat("Enter the next exam score ")
|
||||||
|
# print(type(myScore))
|
||||||
|
scores.append(myScore)
|
||||||
|
print(counter,scores)
|
||||||
|
counter = counter + 1
|
||||||
|
|
||||||
|
return scores
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def getScoreAverage(scores):
|
||||||
|
sumOfScores = 0
|
||||||
|
for dummy in scores:
|
||||||
|
sumOfScores = sumOfScores + dummy
|
||||||
|
|
||||||
|
averageScore = sumOfScores/len(scores)
|
||||||
|
return averageScore
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
# Input 3 float scores from the keyboard and put them in a list.
|
||||||
|
|
||||||
|
scores = getScores(3)
|
||||||
|
|
||||||
|
averageScore = getScoreAverage(scores)
|
||||||
|
|
||||||
|
|
||||||
|
print(f"Average Score is {averageScore:.2f}")
|
|
@ -0,0 +1,67 @@
|
||||||
|
# Program scores2.py
|
||||||
|
# ============================================================
|
||||||
|
def is_float(s):
|
||||||
|
""" Returns True if string is a number. """
|
||||||
|
try:
|
||||||
|
float(s)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def is_int(s):
|
||||||
|
""" Returns True if string is a number. """
|
||||||
|
try:
|
||||||
|
int(s)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def getinteger(Message):
|
||||||
|
myInteger =input(Message)
|
||||||
|
if is_int(myInteger):
|
||||||
|
width = int(myInteger)
|
||||||
|
else:
|
||||||
|
print("This was not an int.")
|
||||||
|
print("Program Terminates in getInteger.")
|
||||||
|
exit(-1)
|
||||||
|
return myInteger
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def getfloat(Message):
|
||||||
|
myFloat =input(Message)
|
||||||
|
if is_float(myFloat):
|
||||||
|
myFloat = float(myFloat)
|
||||||
|
else:
|
||||||
|
print("This was not an float.")
|
||||||
|
print("Program Terminates in getFloat.")
|
||||||
|
exit(-1)
|
||||||
|
return myFloat
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def getScores(numberOfScores):
|
||||||
|
counter = 0
|
||||||
|
scores = []
|
||||||
|
while(counter < numberOfScores):
|
||||||
|
myScore = getfloat("Enter the next exam score ")
|
||||||
|
# print(type(myScore))
|
||||||
|
scores.append(myScore)
|
||||||
|
print(counter,scores)
|
||||||
|
counter = counter + 1
|
||||||
|
|
||||||
|
return scores
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
def getScoreAverage(scores):
|
||||||
|
sumOfScores = 0
|
||||||
|
for dummy in scores:
|
||||||
|
sumOfScores = sumOfScores + dummy
|
||||||
|
|
||||||
|
averageScore = sumOfScores/len(scores)
|
||||||
|
return averageScore
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
# Input 5 float scores from the keyboard and put them in a list.
|
||||||
|
|
||||||
|
scores = [98, 87, 92, 96, 100]
|
||||||
|
|
||||||
|
averageScore = getScoreAverage(scores)
|
||||||
|
|
||||||
|
print(f"Average Score is {averageScore:.2f}")
|
|
@ -0,0 +1,38 @@
|
||||||
|
import sys
|
||||||
|
|
||||||
|
scores = [ 100,100,100]
|
||||||
|
scores1 = [89,96.3,94]
|
||||||
|
|
||||||
|
print("scores = ",scores)
|
||||||
|
print("scores1 = ",scores1)
|
||||||
|
|
||||||
|
scoreCounter = 0
|
||||||
|
scoreSum = 0
|
||||||
|
for aScore in scores:
|
||||||
|
scoreSum = scoreSum + aScore
|
||||||
|
scoreCounter = scoreCounter + 1
|
||||||
|
|
||||||
|
print(scoreSum)
|
||||||
|
print(scoreCounter)
|
||||||
|
print(scoreCounter,scoreSum/scoreCounter)
|
||||||
|
print(len(scores),scoreSum/len(scores))
|
||||||
|
|
||||||
|
# sys.exit(0)
|
||||||
|
|
||||||
|
scoreCounter = 0
|
||||||
|
scoreSum = 0
|
||||||
|
for aScore in scores1:
|
||||||
|
scoreSum = scoreSum + aScore
|
||||||
|
scoreCounter = scoreCounter + 1
|
||||||
|
|
||||||
|
print(scoreSum)
|
||||||
|
print(scoreCounter,scoreSum/scoreCounter)
|
||||||
|
print(len(scores1),scoreSum/len(scores1))
|
||||||
|
|
||||||
|
print("\n")
|
||||||
|
|
||||||
|
print(len(scores1),scoreSum/len(scores1))
|
||||||
|
|
||||||
|
#print(f"len(scores1),scoreSum/len(scores1)")
|
||||||
|
print(f"{len(scores1):d},{scoreSum/len(scores1):.1f}")
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
def getScoreAverage(scoresList):
|
||||||
|
|
||||||
|
scoreSum = 0
|
||||||
|
for aScore in scoresList:
|
||||||
|
scoreSum = scoreSum + aScore
|
||||||
|
|
||||||
|
scoresAverage = scoreSum / len(scoresList)
|
||||||
|
return scoresAverage
|
||||||
|
|
||||||
|
|
||||||
|
scores = [ 100,100,100]
|
||||||
|
scores1 = [89,96,94]
|
||||||
|
|
||||||
|
print("scores = ",scores)
|
||||||
|
print("scores1 = ",scores1)
|
||||||
|
|
||||||
|
scoresAverage = getScoreAverage(scores)
|
||||||
|
print(len(scores),scoresAverage)
|
||||||
|
|
||||||
|
scoresAverage = getScoreAverage(scores1)
|
||||||
|
print(len(scores),scoresAverage)
|
|
@ -0,0 +1,38 @@
|
||||||
|
|
||||||
|
def scoresAverage(scoresList):
|
||||||
|
scoreCounter1 = 0
|
||||||
|
scoreSum1 = 0
|
||||||
|
for aScore in scoresList:
|
||||||
|
scoreSum1 = scoreSum1 + aScore
|
||||||
|
scoreCounter1 = scoreCounter1 + 1
|
||||||
|
return scoreSum1/scoreCounter1
|
||||||
|
|
||||||
|
def scoresSumValue(scoresList):
|
||||||
|
scoreCounter1 = 0
|
||||||
|
scoreSum1 = 0
|
||||||
|
for aScore in scoresList:
|
||||||
|
scoreSum1 = scoreSum1 + aScore
|
||||||
|
scoreCounter1 = scoreCounter1 + 1
|
||||||
|
return scoreSum1
|
||||||
|
|
||||||
|
scores = [ 100,100,100]
|
||||||
|
scores1 = [89,96,94]
|
||||||
|
|
||||||
|
print("scores = ",scores)
|
||||||
|
print("scores1 = ",scores1)
|
||||||
|
|
||||||
|
scoreAverageValue = scoresAverage(scores)
|
||||||
|
print(f"The average is {scoreAverageValue}")
|
||||||
|
|
||||||
|
scoreValue = scoresSumValue(scores)
|
||||||
|
print(f"The sum is {scoreValue}")
|
||||||
|
|
||||||
|
scoreCounter = 0
|
||||||
|
scoreSum = 0
|
||||||
|
for aScore in scores1:
|
||||||
|
scoreSum = scoreSum + aScore
|
||||||
|
scoreCounter = scoreCounter + 1
|
||||||
|
|
||||||
|
print(scoreSum)
|
||||||
|
print(scoreCounter,scoreSum/scoreCounter)
|
||||||
|
print(len(scores1),scoreSum/len(scores1))
|
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
weatherData = {'coord': {'lon': -72.5949, 'lat': 42.1726}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'base': 'stations', 'main': {'temp': 279.29, 'feels_like': 279.29, 'temp_min': 278.09, 'temp_max': 281.43, 'pressure': 1028, 'humidity': 96}, 'visibility': 10000, 'wind': {'speed': 0.45, 'deg': 158, 'gust': 0.89}, 'clouds': {'all': 75}, 'dt': 1698153298, 'sys': {'type': 2, 'id': 2089527, 'country': 'US', 'sunrise': 1698145986, 'sunset': 1698184549}, 'timezone': -14400, 'id': 4933002, 'name': 'Chicopee', 'cod': 200}
|
||||||
|
|
||||||
|
|
||||||
|
jsonWeather = json.dumps(weatherRecord,indent=4 )
|
||||||
|
print("\njsonWeather")
|
||||||
|
print(jsonWeather)
|
||||||
|
|
||||||
|
jsonWeather
|
||||||
|
{
|
||||||
|
"sampleDate": "2023-1024",
|
||||||
|
"sampleTime": "09:19:36",
|
||||||
|
"city": "Chicopee",
|
||||||
|
"state": "Ma",
|
||||||
|
"country": "Us",
|
||||||
|
"latitude": 42.1726,
|
||||||
|
"longitude": -72.5949,
|
||||||
|
"temperature": "43.32",
|
||||||
|
"temperatureUnits": "F",
|
||||||
|
"pressure": "14.91",
|
||||||
|
"pressureUnits": "psi",
|
||||||
|
"humidity": 96,
|
||||||
|
"description": "broken clouds"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue