1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Python checking numbers in a given name

  1. Mar 16, 2015 #1
    1. The problem statement, all variables and given/known data
    I need to write a Python program, which would:

    1) Ask for a name (input function)
    2) Keep asking for the name if it is not entered correctly(if it has a digit in it)
    3) If the name is entered correctly it will print the name

    2. Relevant equations
    How should I continue the program? I tried another way, when I enter for example "J4ck" it asks to enter the name again but when I enter "Jack" for the program to print it, it repeats the name "Jack" 4 times in a row. Any suggestions?

    3. The attempt at a solution
    Code (Text):

    while True:
        name = input("Enter a name: ")
        for x in name:
            if x.isdigit():
                break
     
  2. jcsd
  3. Mar 16, 2015 #2
    Is your instruction to print the name contained within the 'for x in name' loop? If so, the interpreter will print the name as many times as there are letters in the name.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted