# Exercise 10-11 Favorite Number Remembered
# Learning Objective: Save and load JSON using Python. 

import json
from pathlib import Path

path = Path("./Chapter_10/favorite_number2.json")

def get_stored_number():
    if path.exists():
        contents = path.read_text()
        stored_num = json.loads(contents)
        return stored_num
    else:
        get_favorite_number()

def get_favorite_number():
    fav_num = input("Enter your favorite number:  ")
    store_num = json.dumps(fav_num)
    path.write_text(store_num)
    print(f"Favorite number {fav_num} stored.") 

mynum = get_stored_number()
if mynum == None: 
    mynum = get_stored_number()
    print(f'welcome, your favorite number is {mynum}')
else:
    print(f"Stored favorite number: {mynum}")




