Python Python checking numbers in a given name

AI Thread Summary
The discussion centers on creating a Python program that prompts users for a name, ensuring it contains no digits. If a name with digits is entered, the program should continue to prompt for a valid name. A key issue raised is that when a valid name is entered after an invalid one, the program prints the name multiple times, corresponding to the number of characters in the name. The solution involves ensuring that the print statement for the name is outside the loop that checks for digits. This prevents the name from being printed repeatedly and allows for correct output only after a valid name is entered.
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
 
Technology 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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
18
Views
2K
Replies
8
Views
2K
Replies
2
Views
2K
Replies
2
Views
2K
Replies
15
Views
2K
Replies
1
Views
2K
Back
Top