I want to make proram for Gauss Seidel implementation And I want to save every iteration on one JSON But I have some trouble because my code only save the last iteration to Json
import json
iterasi={
"iterasi":None,
"x1":0,
"x2":0,
"x3":0,
}
for x in range (0,11):
iterasi["iterasi"]=x
iterasi["x1"]=6-iterasi["x2"]-iterasi["x3"]
iterasi["x2"]=(2-iterasi["x1"]+iterasi["x3"])/2
iterasi["x3"]=(10-2*iterasi["x1"]-iterasi["x2"])/2
try:
with open("Gauss Siedel.json", "r") as database:
new_data = json.load(database)
except FileNotFoundError:
with open("Gauss Siedel.json", "w") as database:
json.dump(iterasi, database, indent=4)
else:
new_data.update(iterasi)
print(new_data)
with open("Gauss Siedel.json", "w") as database:
json.dump(new_data, database, indent=4)