I am a complete beginner in python (2.7), and this program is supposed to take some students names and their marks in 3 subjects, and return the average of specified name. I did get the answer correctly(through another method), but this program isn't working properly and I want to know why. The main problem is that the list elements with odd indices aren't being deleted. The code is
num=int(raw_input("enter the numbeer of students:"))
d=dict()
marks=[]
for i in range(num):
name=raw_input("enter student name")
j=0
try:
while (j<3):
del marks[j]
j+=1
except:
print "okay!"
print marks
for i in range(3):
marks.append(int(raw_input("enther makrs:")))
print marks,"after"
d[name]=tuple(marks)
req=raw_input("enter the name you want to check")
s=0
for key in d.keys():
if req==key:
n=d[key]
l=list(n)
ave=sum(l)/3
print ave
else:
print "boo"
The output for the above program is:
vamshi@vamshi-HP-Notebook:~/python$ python u.py
enter the numbeer of students:2
enter student namev
okay!
[]
enther makrs:1
enther makrs:2
enther makrs:3
[1, 2, 3] after
enter student namek
okay!
[2] #why isn't this 2 deleted?
enther makrs:5
enther makrs:6
enther makrs:7
[2, 5, 6, 7] after
enter the name you want to check
Thanks in advance