我正在尝试获取班级中每个人的姓名和国家/地区代码,并将它们放入元组列表中。我的麻烦是,如果name
不是字母,它不会循环播放。有帮助吗?
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)
[当我自己在python 3.6和3.7上运行原始版本时,我发现它确实循环了。您确定这是问题所在吗?
简体:
print(input('Input: ').isalpha())
例如测试:
>>> print(input('Input: ').isalpha())
Input: 123
False
>>> print(input('Input: ').isalpha())
Input: abc
True
>>> print(input('Input: ').isalpha())
Input: abc123
False