Q:

Center str in python 2.7

i'm trying to center the text of a string but i can't do it. I checked mutiple posts and tried  what they said, i don't get an error but the text is still aligned to the left. here the code and the str i want to center
while True:
        print ''
        while True:
                try:
                    userNum = float(raw_input('Enter the total of your bill: '))

                    if (userNum) > 0 and (userNum) != 0:
                        break
                    else:
                        print 'Oops!  That was no valid number.  Try again...'

A:

You could use str.format. The ^80  format tells Python to make the string 80 characters long, and to center the argument:
print('{:^80}'.format('Oops!  That was not a valid number.  Try again...'))

yields
               Oops!  That was not a valid number.  Try again...                

