Comparing numbers give the wrong result in Python

前端 未结 4 1915
余生分开走
余生分开走 2020-11-29 12:59

If I enter any value less than 24, it does print the \"You will be old...\" statement. If I enter any value greater than 24 (ONLY up to 99), it prints the \"you are old\" st

4条回答
  •  自闭症患者
    2020-11-29 13:24

    Use int(myAge). I always use raw_input and also, you dont have to print your questions. Instead put the question in with your raw_inputs like so:

    myName = raw_input("Whats your name?")
    print ('Hello, ' + myName)
    myAge = raw_input('How old are you?, ' + myName)
    if int(myAge) > ('24'):
        print('You are old, ' + myName)
    else:
        print('You will be old before you know it.')
    

提交回复
热议问题