【发布时间】:2021-11-30 16:04:32
【问题描述】:
这里是代码sn-p。
我试图让用户输入他们的姓名和年龄,以输出他们将在哪一年 100 岁。
然后我向用户询问一个数字,并希望将字符串重复 x 次。
当我尝试使用换行符 '\n' 时,我收到了意外的字符错误。不确定我应该去哪里。
name = input ("What is your name: ")
age = input("what is your age: ")
age = int(age)
howLong = (100 - age) + 2021 #calculates the year
times = input("Pick a number: ")# asks user for a year
print(int(times) * (name+" will be 100 years old in: " + str(howLong))) #tells what year it will be
我试过了
print(int(times) * ('name+" will be 100 years old in: " + str(howLong))\n') #tells what year it will be
还有
print(int(times) * (name+" will be 100 years old in: " + str(howLong))'\n') #tells what year it will be
还有
print(int(times) * (name+" will be 100 years old in: " + str(howLong))\n) #tells what year it will be
还有
print(int(times) * ('''name+" will be 100 years old in: " + str(howLong))'''\n) #tells what year it will be
它似乎不起作用。任何指针?是的,这是作业,这部分是奖金。试图弄清楚。
【问题讨论】:
标签: python string output repeat