一个程序,询问用户年龄,并告诉用户他/她何时将满100岁

时间:2017-07-20 06:56:23

标签: python

创建一个程序,要求用户输入他们的姓名和年龄。打印一封发给他们的信息,告诉他们他们将在100岁前完成这一年。

这是我的代码不起作用:

username=input("Please enter your name")
userage=input("Please enter your age")

def age100(userage):

   turn=100-userage+2017

   return turn


age100(userage)

message= 'Hello %s, your age is %d and you will turn 100 in the year %d' %(username,userage, turn)
print(message)

1 个答案:

答案 0 :(得分:-1)

您调用该函数,但从不保存或使用结果。这应该解决它:

username=input("Please enter your name")
userage=input("Please enter your age")

def age100(userage):

   turn=100-userage+2017

   return turn


turn = age100(userage)

message= 'Hello %s, your age is %d and you will turn 100 in the year %d' %(username,userage, turn)
print(message)