Reputation: 33
First, I am new to programming in general, so that means I'm new to python as well, so type slowly so I can keep up. I am trying to center a line of text that includes a variable that was input by a user. Something like this:
age = input ("How old are you? ")
print ("{: ^80}".format("You are", (age), "years old."))
I've tried as many ways as I can think of to get this to center the entire line reading . . . You are 40 years old. (Assuming, of course, the user input = 40) with no luck. What am I doing wrong?
Thanks, Robert
Upvotes: 3
Views: 210
Reputation: 1664
Using .center() on strings will pad them with spaces on both sides.
print('You are {} years old'.format(age).center(80))
Upvotes: 1