Python ValueError:以10为基数的int()的文本无效:';跳过'; def intro(): 全局跳过 跳过=3 打印('跳过') 跳过=int(输入()) 如果跳过中的“跳过”: 跳过-1 如果跳过>0: 打印('跳过项已用完') 完() 如果跳过
我希望每次有人输入(跳过)时,它也被拿走(跳过1次)。每次它在程序中运行时,我希望它检查是否有足够的(跳过)。非常感谢您的帮助。这更接近您想要的:Python ValueError:以10为基数的int()的文本无效:';跳过'; def intro(): 全局跳过 跳过=3 打印('跳过') 跳过=int(输入()) 如果跳过中的“跳过”: 跳过-1 如果跳过>0: 打印('跳过项已用完') 完() 如果跳过,python,Python,我希望每次有人输入(跳过)时,它也被拿走(跳过1次)。每次它在程序中运行时,我希望它检查是否有足够的(跳过)。非常感谢您的帮助。这更接近您想要的: def intro(): global skips skips = 3 print ('skip') skips = int(input()) if 'skip' in skips: skips - 1 if skips > 0: print('y
def intro():
global skips
skips = 3
print ('skip')
skips = int(input())
if 'skip' in skips:
skips - 1
if skips > 0:
print('you are out of skips')
end()
if skips < 0:
print ('You have ' ,skips, ' left')
intro()
def end():
print ('you are out of skips. Game Over')
intro()
def简介(跳过=3):
打印('跳过')
答案=输入()
如果回答为“跳过”:
跳过-=1
如果跳过0:
打印('youhave',skips',left')
简介(跳过)
def end():
打印('跳过了,游戏结束')
简介()
你怎么知道有人键入了“skip”?skips-1
什么都不做……发生错误的原因是你键入了“skip”,它由input()
读取,然后传递到int()
上,试图转换成整数,因此引发了ValueError
你认为int(input())怎么样
正在做什么?谢谢。这就是我想要的。
def intro(skips=3):
print ('skip')
answer = input()
if 'skip' in answer:
skips -= 1
if skips <= 0:
print('you are out of skips')
end()
elif skips > 0:
print ('You have ' ,skips, ' left')
intro(skips)
def end():
print ('you are out of skips. Game Over')
intro()