我几乎拥有它!此代码询问您的姓名,年龄,并询问是否需要更多副本。如果是,则询问多少。我正在寻找代码将字符串打印在不同的行中,而不是一行。我试图使用一个循环,但没有弄清楚如何构造它。谢谢你的时间。
def mynameandage():
name = (input(" Hey, What's your name?"))
age = int(input(" and how old are you?"))
hundred = ((100-age)+2019)
copias1=(input("Would you like more copies of this info?"))
displaytext= (f'{name} you will be 100 years old in the year {hundred}. ')
if copias1 =='yes':
cuantas= int(input("how many?"))
return (f" {displaytext} " *cuantas)
else:
return (f'Okay but remember that {displaytext}')
mynameandage()
答案 0 :(得分:1)
我认为您只需要在\n
的末尾添加{displaytext}
:
def mynameandage():
name = (input(" Hey, What's your name?"))
age = int(input(" and how old are you?"))
hundred = ((100-age)+2019)
copias1=(input("Would you like more copies of this info?"))
displaytext= (f'{name} you will be 100 years old in the year {hundred}. ')
if copias1 =='yes':
cuantas= int(input("how many?"))
return (f" {displaytext}\n" * cuantas)
else:
return (f'Okay but remember that {displaytext}')
mynameandage()