The loop problem lies in the fact that you are using the raw_input
function to assign the value to the variable resp
and to be comparing this value with an integer.
If the user types 0
, the value that is stored in resp
is "0"
(a string containing the 0
character).
To solve the infinite loop problem, simply substitute line 6 for:
while resp != "0":
Some considerations regarding your code:
- Try to be homogeneous in the spacings and follow a pattern. Try to use
a = int(a)
, instead of a= int (a)
. Good practices are found in Python Enhancement Proposal
(PEP). I suggest you read at least PEP 8: link .
- On line 29 you do an unnecessary check. For the program to arrive there, it is guaranteed (see line 16) that
a != ''
.