如何多次打印行并始终使用新行缩进?

问题描述 投票:0回答:2

我试图多次打印一行,但无法使它们缩进新行,请支持。

code:

  Input_Name = input('please enter your Name')
   Input_age = int(input('please enter your Age'))
   Input_a_Number = int(input('please enter another number'))
   Difference_Number = 100 - Input_age
   print(( "Dear",Input_Name,"you will get 100 years old after" ,Difference_Number, "years", 
   "\r\n")*Input_a_Number)

结果:

please enter your Names
please enter your Age2
please enter another number3
('Dear', 's', 'you will get 100 years old after', 98, 'years', '\r\n', 'Dear', 's', 'you will get 100 years old after', 98, 'years', '\r\n', 'Dear', 's', 'you will get 100 years old after', 98, 'years', '\r\n')
python indentation
2个回答
0
投票

尝试运行它。

Input_Name = input('please enter your Name')
Input_age = int(input('please enter your Age'))
Input_a_Number = int(input('please enter another number'))
Difference_Number = 100 - Input_age
print(("Dear " + str(Input_Name) + " you will get 100 years old after " +
   str(Difference_Number) + " years" + "\n")*Input_a_Number)

或根据需要使用逗号

Input_Name = input('please enter your Name')
Input_age = int(input('please enter your Age'))
Input_a_Number = int(input('please enter another number'))
Difference_Number = 100 - Input_age
print(('("Dear", Input_Name, "you will get 100 years old after", 
Difference_Number, "years", )' + '\n')*Input_a_Number)
© www.soinside.com 2019 - 2024. All rights reserved.