Completed 10-11 Favorite Number

This commit is contained in:
cheeks 2025-03-07 23:13:11 +00:00
parent 0420c90a99
commit a4e50e9cb7
3 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,15 @@
# Exercise 10-11 Favorite Number
# Learning Objective: Save data in JSON format.
import json
from pathlib import Path
path = Path("./Chapter_10/favorite_number.json")
favorite_number = input("What is your favorite number?")
path.write_text(json.dumps(favorite_number))

View File

@ -0,0 +1,12 @@
# Exercise 10-11b Favorite Number
# Learning Objective: Load stored JSON formatted data.
import json
from pathlib import Path
path = Path("./Chapter_10/favorite_number.json")
contents = path.read_text()
favorite_number = json.loads(contents)
print(f"I know your favorite number. It's {favorite_number}.")

View File

@ -0,0 +1 @@
"21343524"