Learning Python: If condition executing all the time

后端 未结 5 1508
情深已故
情深已故 2021-01-21 05:33

I am learning python and i can\'t figure out why the following program is printing your number is greater than what i thought even when the guessed number is sm

5条回答
  •  鱼传尺愫
    2021-01-21 06:34

    I didn't know this until just now, but as it turns out, a string will always be "greater than" an integer in Python:

    >>> "0" > 1
    True
    

    All you need to do is replace

    guess = raw_input ("Guess:")
    

    with

    guess = int(raw_input ("Guess:"))
    

提交回复
热议问题