我试着做一个简单的程序,让用户输入name
和{
我要等到20岁才有结果
Congratulation Edit your age is 20 and you can find the truth
但它不起作用这是我用的代码。在
编码
name = input("what is your name \n")
print('Nice to meet you', name, "!!")
age = input("Your Age ? \n")
if age > 18:
print('Congratulation ' + name + ' your age is '+ str(age), ' and you can find the truth ')
else:
print('Sorry ' + name + 'your age is '+ str(age), ' and you can also find the truth if you start from today')
以及运行代码后遇到的错误。在
错误
^{pr2}$帮我解决这个问题。在
阅读错误消息:
您正在尝试比较字符串和整数。必须先将输入转换为
^{pr2}$int
:这将允许你将它与数字进行比较。在
或者,在需要与数字比较时转换它
但这实际上是一个可用性问题。最好一得到它就把它转换成
int
,因为年龄的增长,你可能更需要数值而不是字符串值。在相关问题 更多 >
编程相关推荐