I am trying to get the names and country codes for each person in the class and putting them into a list of tuples. My trouble is that it is not looping back if name
is not alphabetic. Any help?
mylist = []
for x in range(2):
while True:
name = input("what is your name?: ")
numCode = input("what is your country phone code? (+44): ")
if name.isalpha():
break
mylist.append([name, numCode])
print(mylist)
edit Here it shows the program breaks and continues to the next logic even if name.isalpha()
is false
what is your name?: 11
what is your country phone code? (+44): aa
what is your name?: 11
what is your country phone code? (+44): aa
what is your name?: aa
what is your name?: 11
what is your country phone code? (+44): 11
what is your name?: aa
[['aa', 'aa'], ['aa', '11']]
When running the original myself on python 3.6 and 3.7 I found that it did loop back. Are you sure this is the problem?
Simplified:
print(input('Input: ').isalpha())
eg tests:
>>> print(input('Input: ').isalpha())
Input: 123
False
>>> print(input('Input: ').isalpha())
Input: abc
True
>>> print(input('Input: ').isalpha())
Input: abc123
False
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.