[英]Python: collect data from multiple lines at a time and print the results in order
[英]Print multiple time on different lines Python
我写了一个代码,我想在不同的行上打印多次,我写了下面的代码,我的问题是关于最后一行代码。
import math
# Make an program, ask the user how old he or she is and tell them the year
# they turn 100
name = input("What is your name? ")
age = input("How old are you? ")
random_number = input("Please give a random number between one and ten: ")
age = int(age)
random_number = int(random_number)
year_awnser = 100 - age
year_awnser = int(year_awnser)
print(f"It will take {year_awnser} years until you are 100")
awnser = 2020 + year_awnser
awnser = int(awnser)
print(f"{name} you will be 100 in: {awnser}")
print("\n")
# Print the message above, times given by the random_number.
print(f"{name} you will be 100 in: {awnser}. " * random_number)
谁能帮我解决这个问题?
谢谢!
如果你想使用你的代码,只需添加'\n'
标签:
print(f"{name} you will be 100 in: {awnser}. \n" * random_number)
我建议使用循环,因为它给人更好的印象并澄清了代码。 print 方法中有一个内置的'\n'
标签:
for times in range(random_number):
print(f"{name} you will be 100 in: {awnser}. ")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.