不问问用户输入,当他们键入字母时,它会出现一个错误消息(如我想),但即使用户输入数字时出现错误。如果输入的是正确的数据,我希望它从这个循环中出来,然后放到下一个名称中。Python 3.4.2循环不
回答
input
总是返回文本 - 即使只有数字。
使用int(Telephone)
转换为整数或Telephone.isdigit()
检查文本中是否只有数字。
BTW:这两种方法是,如果用户使用的空间或电话号码-
没用;)
也许你将不得不使用int()
或isdigit()
OP,请查看['int()'](https://docs.python.org/2/library/functions.html#int)。 – Sam
replace()
空间和
-
您需要转换为int:
while True:
try:
Telephone = int(input("Please enter your telephone number "))
break
except ValueError:
print ("Sorry, system does not recognise input ")
说'catch'无效的语法 – Programmer
即使使用此代码并将catch更改为除except它运行,并且每次运行时问题只是不断重复,当它应该移动到下一个循环 – Programmer
看看我添加的新主题混淆 – Programmer
- 1. Python 3.4.2 |循环输入,直到设定的数量
- 2. 如何在Python 3.4.2
- 3. for循环不够循环 - Python
- 4. Python 3.4:while循环不循环
- 5. TypeError:'int'对象不可下载Python 3.4.2
- 6. Python中嵌套循环(列表理解);外循环不循环
- 7. 循环python中的循环
- 8. Python 3.4.2列表添加
- 9. 在python 3.4.2中打印
- 10. Python 3.4.2语法错误
- 11. Python 3.4.2输出格式化
- 12. python 3.4.2 urlib无属性'pathname2url'
- 13. Python while循环不停止?
- 14. while循环不退出Python
- 15. While循环不会在Python
- 16. Python循环不会继续
- 17. Python菜单不循环?
- 18. Python while循环不稳定
- 19. 循环不会在Python
- 20. python tcpserver不要循环
- 21. 不能摆脱Python循环
- 22. 的Python不定循环
- 23. Python双循环
- 24. Python - While循环
- 25. 循环python
- 26. python循环!
- 27. Python inFile循环
- 28. Python - For循环
- 29. Python for循环?
- 30. python subplot循环
阅读[input()文档](https://docs.python.org/3/library/functions.html#input)。该函数总是返回一个字符串,而不是一个整数。 – skrrgwasme