Search code examples
pythonstringvariablesmultiplication

Python - how to make new text to be in multiply lines after variable?


name = input("what is your name? ")
age = int(input("what is your age? "))
year = str((2021 - age) + 100)

print(name , ", you'll be 100 in" , year , " !")

number = int(input("type in a number: "))
text = print('\n', name , ", you'll be 100 years old in" , year , " !")
x = 1

if x <= number:
   print(text)
if x <= number:
    x = x + 1
if x == number:

and the output should be:

number = 3

output:

text

text

text

After trying while loops and if statements I get:

number = 3

output:

text

[none]

[none]


Solution

  • This line is causing the issues:

    text = print('\n', name , ", you'll be 100 years old in" , year , " !")
    

    The return of a print() statement is None, so in that line text = None. Meaning, when you print text, you are printing None.

    You can rewrite it like this:

    text = f"\n{name}, you'll be 100 years old in {year}!"
    print(text)