Python checking numbers in a given name

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 1K views
acurate
Messages
17
Reaction score
1

Homework Statement


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

Homework 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?

The Attempt at a Solution


Code:
while True:
    name = input("Enter a name: ")
    for x in name:
        if x.isdigit():
            break
 
Physics news on Phys.org
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.