Dicts + JSON
revisiting code from yesterday
https://replit.com/@MarkSantolucito/dicts
We want to print the student name alongside each grade
then
We want to calculate the average of each student
revisiting code from yesterday
https://replit.com/@MarkSantolucito/dicts
We want to print the student name alongside each grade
then
We want to calculate the average of each student
Next: let’s make an interactive version where we can input students and grades
Interactive gradebook
Allow user to:
add_student(gradebook, student): adds a student with no grades to the gradebook, if student already exists, do nothing. return the updated gradebook.
add_grade(gradebook, student, assignment, grade): add a grade to that student, return the updated gradebook
Write these functions (API), then add a loop to allow user to select which to call
saving state in files
JSON - Javascript Object Notation
at this point, basically nothing to do with javascript
just a file format for saving dictionaries
Also common: YAML
JSON: often used for data (but not too much data)�YAML: a bit more human readable, often used for configuration files
A quick note on databases
NoSQL vs MySQL
e.g. MongoDB
JSON basics in python
import json
sample = {"test": 36}�
with open('data.json', 'w') as json_file:
json.dump(sample, json_file)
with open('data.json') as json_file:
data = json.load(json_file)
print(data["test"])
reading and writing other files
Interactive gradebook
Allow user to:
add_student(gradebook): adds a student with no grades to the gradebook, if student already exists, do nothing. return the updated gradebook.
add_grade(gradebook, student, assignment, grade): add a grade to that student, return the updated gradebook
save_gradebook(gradebook, fp): writes the gradebook to a json file, no return
load_gradebook(fp): returns loaded gradebook
Write these functions (API), then add a loop to allow user to select which to call
Intro to HW3
to be posted when get here
https://replit.com/@MarkSantolucito/IEE1164Homework3
also, what to do tomorrow?