创建一个程序,要求用户输入他们的姓名和年龄。打印一封发给他们的信息,告诉他们他们将在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)
答案 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)