[英]Why isn't this code not working properly? Python loop not breaking properly [on hold]
我试图获取班上每个人的姓名和国家/地区代码,并将它们放入元组列表中。 我的麻烦是,如果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)
编辑这里,即使name.isalpha()
为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']]
当我自己在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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.