是否可以将这个打印行分开,以便它打印在单独的行上而不是打印在一行上?

问题描述 投票:0回答:1
your_name = input("Please tell me your name:  ")
your_age = int(input("Please tell me your age:  "))
print_times = int(input("How many times would you like to print this message? "))
years_old = 2023 + 100 - your_age
print(("Hi ", your_name + " ", "you will be 100 years old in ", years_old)  *  print_times)
python printing newline
1个回答
0
投票

而不是

print(("Hi ", your_name + " ", "you will be 100 years old in ", years_old)  *  print_times)

您可以使用更具可读性的 f 字符串与 ' ' 分隔输出:

print(f'Hi, {your_name}, you will be 100 years old in {years_old} \n' * print_times)
© www.soinside.com 2019 - 2024. All rights reserved.