小编Ras*_*ian的帖子

比较数字会在Python中产生错误的结果

对不起,如果这是一个可怕的问题,但我真的很喜欢编程.我正在尝试一个简短的小测试程序.

如果我输入任何小于24的值,它会打印出"你将老了......"的声明.如果我输入任何大于24的值(仅限最多99),则会打印"你是旧的"语句.

问题是如果你输入一个100或更大的值,它会打印出"在你知道之前你会老去".声明.

print ('What is your name?')
myName = input ()
print ('Hello, ' + myName)
print ('How old are you?, ' + myName)
myAge = input ()
if myAge > ('24'):
     print('You are old, ' + myName)
else:
     print('You will be old before you know it.')
Run Code Online (Sandbox Code Playgroud)

python if-statement

4
推荐指数
1
解决办法
4542
查看次数

标签 统计

if-statement ×1

python ×1