-1
a= int(input("Enter number of students:"))
i=1
n = []
t = []
p = []
avg = []

while i<=a:
    total=0
    name = input("Enter name of student:")
    n.append(name)
    subjects = int(input("Enter count of subjects:"))
    i=i+1
    j=1
    while j<=subjects:
        s = int(input("Enter marks:"))
        total = total + s
        j=j+1
        percentage = (total/(subjects*100))*100
        average = total/subjects
    t.append(total)
    p.append(percentage)
    avg.append(avg)
    
    
    result = dict(zip(n,p))
    
    
    print("Total marks of", name, "is", total)

print("The students:",n)
print("The total of students:",total)
print("The average of students:",avg)
print("The percentage of students:", percentage)
print("The result of students:", result)   

i want to store the data which I get from this code and later on display specific data like if I search for student's name, I'll get his marks and average. how do I do this?

DDS
  • 1
  • 1
  • It would be better to explain what problem you encountered to solve what issues and what are the expected output in detail. Otherwise, users should spend much time to understand your question. – Park Jan 24 '22 at 07:55
  • Do you mean to store the resulting dict in a file? – RJ Adriaansen Jan 24 '22 at 07:59
  • Maybe take a look at this: https://stackoverflow.com/questions/11218477/how-can-i-use-pickle-to-save-a-dict, if you wish to store and use the dict later. – Dilith Jayakody Jan 24 '22 at 08:12

1 Answers1

0

First get the name. Then find the index of that. Now search for the marks, average etc in the arrays. Keep in mind that this will only work when the indices are same for each student data. Imagine that the arrays are stacked on top of each other, the data for each student should be in a straight line(You have done that only here).Oh, and one more thing, they are called arrays, not dictionaries. Dictionaries are initialized with {}(curly brackets). Here is a sample code:

n=["S1","S2"]
t=[100,70]
avg=[30,20]
#say you want to get the data of S2
i=n.index("S2")
print("Student name: "+str(n[i])+" Student total marks:"+str(t[i])+" Student average: "+str(avg[i]))
Jishnu Das
  • 1
  • 1
  • 2