1. Limited time only! Sign up for a free 30min personal 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!

Homework Help: 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():
  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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted