简体   繁体   English

Python 3 中的跳过行

[英]Skip lines in Python 3

Just started learning.刚开始学习。 Trying to figure out how to skip a line in the Times = (Times * int(Random_Number)) ,试图弄清楚如何在Times = (Times * int(Random_Number))跳过一行,

to be something like :是这样的:

print(Times)

print(Times)

Etc..等等..

Year = input("Now's year : ")
name= input("Enter your name: ")
Initial_age= float(input(("Enter your age: ")))

Final_age= float(Year) + (100 - Initial_age)
Times =(name+ " You're turning"+ " 100 at year " + str(Final_age))

Random_Number = (input("Enter a random number: "))
Times = (Times * int(Random_Number))

print(Times)

If you want to print each NAME You're turning 100 at year XXXX on a new line, like this如果你想打印每个NAME You're turning 100 at year XXXX的时候换一行,像这样

John You're turning 100 at year 2109.0
John You're turning 100 at year 2109.0
John You're turning 100 at year 2109.0
John You're turning 100 at year 2109.0

Add a \\n at the end here在此处末尾添加\\n

Times = name + " You're turning 100 at year " + str(Final_age) + "\n"

But the nicest is to use a loop, and a print inside of it但最好的是使用循环,并在其中print

year          = int(input("Now's year : "))
name          = input("Enter your name: ")
initial_age   = int(input("Enter your age: "))
random_number = int(input("Enter a random number: "))

final_age = year + 100 - initial_age
for i in range(random_number):
    print(name, "You're turning 100 at year", final_age)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM