0
building a list (help)
#building a list print("Enter number of courses, please: ") len=input() i=0 b=[] print("enter all the grades: ") while True: x=input() b.append(x) if i==int(len): break i+=1 print(b) Whatâs wrong With my code? It writes that there is a problem in line 7
2 Answers
+ 1
You're code asks for one more than you enter at the beggining. eg. when you enter 3, it expects 4 values.
i would try a for loop, or set what i call a "loop switch".
eg:
for i in range(int(len)):
x = input()
...
#OR
RUNNING = True
while(RUNNING):
x = input()
...
if <stop condition>:
RUNNING = False
+ 1
thanks ,actually i found that the problem was in i==len ......should be i==int(len)-1:
because i was compered to str value of len