2024-04-19 00:30:29 发布
网友
我已经创建了一个Python脚本来获取用户的手机号码
我需要得到整数
所以我用
Mobile=int(input("Enter the Mobile Number: "))
在运行我的程序时,如果输入任何字符而不是整数,程序将崩溃并产生错误消息
但是,我需要的是,它必须给出错误信息,并且必须再次运行以询问手机号码
请让我知道路
while True: given = input("Enter the Mobile Number: ") try: mobile = int(given) break except Exception: print("Invalid input, should only contain numbers") print("entered number is", mobile)
相关问题 更多 >
编程相关推荐