Skip to main content
 首页 » 编程设计

python之如果不工作

2025年05月04日30jirigala

<分区>

我正在尝试制作一个简单的程序,要求用户输入 name 和 age,然后使用 if else 打印结果。

我想要什么时候放 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') 

以及运行我的代码后出现的错误。

错误

what is your name  
Edit 
Nice to meet you Edit !! 
Your Age ?  
20 
Traceback (most recent call last): 
  File "C:/Users/hp/PycharmProjects/Project/input_user.py", line 5, in <module> 
    if age > 18: 
TypeError: unorderable types: str() > int() 

帮我解决这个问题。