【发布时间】:2021-04-12 09:12:22
【问题描述】:
我正在尝试使此代码正常工作,如果您输入一个数字,它将使您返回到 name=input 提示,并且一旦您输入字母字符而不是数字字符,它将允许您继续下一个一组代码,但它不断将您返回到 name = input 并且不允许您完成其余代码
def setup():
global name
global HP
global SP
global MP
while True:
try:
name = input('can you please tell me your name? ')
name2=int(name)
if not name.isalpha==True and not name2.isdigit==False:
break
except Exception:
print('please input your name')
continue
HP = randint(17,20)
SP = randint(17,20)
MP = randint(17,20)
print('welcome ['+name+':]: to the moon landing expedition')
【问题讨论】:
-
ps这是一个学校项目
标签: python-3.x while-loop