我刚刚开始学习编程,并且正在研究一些问题。 在我现在要执行的操作中,我应该询问用户的姓名和年龄,并返回一条消息,告诉他们他们将在哪年100岁。之后,我要询问他们要多少次。查看消息并打印消息输入的次数。 但是,我返回“无”的次数是他们输入的次数,而不是消息本身。为什么会这样,我该如何解决?
def name_age(year=2019):
name = input('What is you name? ')
age = int(input('What is your age? '))
new_age = year - age + 100
message = print('Hello {}, you will turn 100 in the year {}'.format(name,new_age))
rep = int(input('How many times would you like to see this message? '))
for num in range(0,rep):
print(message)
这就是我得到的:
What is you name? Emily
What is your age? 23
Hello Emily, you will turn 100 in the year 2096
How many times would you like to see this message? 2
None
None