0

The following is my code, I want to ask a number to work on, check if it is digit before asking for another options, and if is another valid digit, break while loop.

I understand that I could ask two question before using and operand to join the two condition in one if. But surprisingly my python program ALWAYS hang (not responding) while I run, with the following code. I try troubleshooting and realise it's having another raw_input in the if loop, anyone facing the same problem ? Or is there something that I missed out ?

while True:
    testNo = raw_input("Enter the number you want to test:")
    if testNo.isdigit() == True:
        testOp = raw_input("Choose your option:1 - double, 2 - square, 3 - cube:")
        if testOp > 0 and testOp <= 3:
            break
        else:
            continue
    else:
        continue
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Jun Wei
  • 151
  • 1
  • 3
  • `testOp` is a string, not an integer, so comparing to integers has no real meaning. Numbers are considered smaller than strings in Python 2, so `testOp > 0` is always true, `testOp <= 3` is always false, regardless of the contents of the string. – Martijn Pieters Oct 08 '16 at 16:25
  • Thanks for the prompt response, but even after changing to int(testOp) it still hanged, my Python shell program becomes "Not responding" after i pressed F5, or Run module. – Jun Wei Oct 09 '16 at 04:17

0 Answers0