current_choice="-"
computer_parts=[] #Create an empty list
while current_choice!=0:
if current_choice in "12345":
print("Adding {}".format(current_choice))
if current_choice== "1":
computer_parts.append("Computer")
elif current_choice== "2":
computer_parts.append("mouse")
elif current_choice== "3":
computer_parts.append('Keyboard')
elif current_choice== "4":
computer_parts.append('monitor')
elif current_choice== "5":
computer_parts.append('Mouse mat')
else:
print("Add from the list below")
print("1:Computer \n"
"2: mouse \n"
"3:Keyboard \n"
"4:monitor \n"
"5: Mouse mat \n"
"0: to finish")
current_choice=input()
print(computer_parts)
Asked
Active
Viewed 14 times
0
MegaIng
- 6,933
- 1
- 21
- 34
Kashish Dhir
- 9
- 1
-
In your own words, why should the loop ever exit? (Hint: is the integer `0` equal to the string `"0"`?) – Karl Knechtel Jul 01 '21 at 10:46
-
`input()` returns a string – Tom McLean Jul 01 '21 at 10:48