I already have this python code for json. I just need to make it display the data in tabular format, including an additional column showing each student’s average to the right of that student’s three exam grades and an additional row showing the class average on each exam below that exam’s column. There is also a example pic of how it should look like. Code below: import json def main(): n = int(input("Enter the number of students: ")) data=[] for i in range(n): first = input("\nEnter First Name of Student "+str(i+1)+": ") last = input("Enter Last Name of Student "+str(i+1)+": ") te1 = int(input("Enter Te_st 1 Grade of Student "+str(i+1)+": ")) te2 = int(input("Enter Te_st 2 Grade of Student "+str(i+1)+": ")) te3 = int(input("Enter Te_st 3 Grade of Student "+str(i+1)+": ")) info={} info['first_name']=first info['last_name']=last info['ex_am1']=te1 info['ex_am2']=te2 info['ex_am3']=te3 data.append(info) gradebook_dict ={'students':data} with open("grades.json",'w') as _file: json.dump(gradebook_dict ,_file,indent=4) print("\nWriting Done.\n") with open("grades.json",'r') as _file: data = (json.load(_file))['students'] for i in data: print(i) main()
I already have this python code for json. I just need to make it display the data in tabular format, including an additional column showing each student’s average to the right of that student’s three exam grades and an additional row showing the class average on each exam below that exam’s column. There is also a example pic of how it should look like.
Code below:
![First
Bob
Sue
Last
Jones
Smith
Doe
Karen
Test Averages
Test1 Test2 Test3
86
75
84
99
77
88
83
88
92
89.33 80.00
80.00
Average
81.67
88.00
87.67](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F05326652-a992-44c1-99fc-81105932e581%2F5e516c2c-a168-40ad-af67-0718b1c91b96%2Fujmy9ku_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Code:-
import json
def main():
n = int(input("Enter the number of students: "))
data=[]
for i in range(n):
first = input("\nEnter First Name of Student "+str(i+1)+": ")
last = input("Enter Last Name of Student "+str(i+1)+": ")
te1 = int(input("Enter Te_st 1 Grade of Student "+str(i+1)+": "))
te2 = int(input("Enter Te_st 2 Grade of Student "+str(i+1)+": "))
te3 = int(input("Enter Te_st 3 Grade of Student "+str(i+1)+": "))
info={}
info['first_name']=first
info['last_name']=last
info['ex_am1']=te1
info['ex_am2']=te2
info['ex_am3']=te3
data.append(info)
gradebook_dict ={'students':data}
with open("grades.json",'w') as _file:
json.dump(gradebook_dict ,_file,indent=4)
print("\nWriting Done.\n")
with open("grades.json",'r') as _file:
data = (json.load(_file))['students']
print(f'{"First Name":>15} {"Last Name":>15} {"test 1":>6} {"test 2":>6} {"test 3":>6} {"average":>7}')
totalTest1=0
totalTest2=0
totalTest3=0
count=0
for i in data:
t1=i['ex_am1']
t2=i['ex_am2']
t3=i['ex_am3']
totalTest1+=t1
totalTest2+=t2
totalTest3+=t3
count+=1
fname=i['first_name']
lname=i['last_name']
avg=(t1+t2+t3)/3
print(f"{fname:>15} {lname:>15} {t1:>6d} {t2:>6d} {t3:>6d} {avg:>7.2f}")
print("-"*60)
print(f"{'Test average':<32} {totalTest1/count:>6.2f} {totalTest2/count:>6.2f} {totalTest3/count:>6.2f}")
main()
Step by step
Solved in 2 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)