3

So this is my code:

name = input("So, what is your name? ")
    if name.isalpha():
    print ("So your name is " +(name) + "? Awesome.")
    else:
    print ("That's not a real name! Try again...")

I want to figure out how to return to the original question after the player doesn't type in a real name. This is my first day of using Python (and any language, really) so don't use anything too advanced for me :)

Also, how can I make the first letter of the players name automatically capitalize if it isn't already?

user2975375
  • 81
  • 1
  • 1
  • 7

1 Answers1

4

You can use while loop like this

name = input("So, what is your name? ")
while not name.isalpha():
    print ("That's not a real name! Try again...")
    name = input("So, what is your name? ")
print ("So your name is " +(name) + "? Awesome.")

First, it gets the name, and the while loop makes sure that as long as the name not only has alphabets, it will print That's not a real name! Try again... and take input for name. If the name has only alphabets it automatically breaks out of the loop and prints "So your name is <name entered>? Awesome."

Edit: To make the first character an uppercase letter, you can use title function and instead of concatenating strings, you can format them like this.

print ("So your name is {}? Awesome.".format(name.title()))
thefourtheye
  • 233,700
  • 52
  • 457
  • 497
  • Ok. Wait. This comment section is annoying :| Thanks @thefourtheye! I didn't know I could do that. I was doing something similar, but instead I would set a new variable equal to the old variable, but capitalized and that didn't work, but what you said did work! – user2975375 Nov 10 '13 at 03:45
  • Then just do `name = name.title()` – thefourtheye Nov 10 '13 at 03:45