我试图在Python中运行为21点游戏编写的以下模块,但是出现了一个错误:
Unindent does not match any outer indentation level.问题
python检查器检查它们,而我知道这只是一个很容易使用的选项,而无需在python中添加代码,只需运行它来检查代码被破坏的位置?示例
如果截图不清楚:
koloda = [6,7,8,9,10,2,3,4,11] * 4
import random
random.shuffle(koloda)
print(' Lets play blackjack, shall we? ')
count = 0
while True:
choice = input(' Will you pick another card? y/n\n ')
if choice == ' y ':
current = koloda.pop()
print(' You got a higher card %d ' %current)
count += current
if count > 21:
print(' Sorry, you lost ')
break
elif count == 21:
print(' Congrats, you got 21! ')
break
else:
print(' You have %d points. ' %count)
elif choice -- 'n':
print(' You have %d points and you ended this game. ' %count)
break
print('See you again!')提前感谢
发布于 2015-12-11 15:50:46
你的契约不一致。在python中,您可以选择如何缩进块(例如制表符、4个空格、3个空格.),但您应该始终坚持最初的选择。否则会出现缩进错误。
关于另一个问题,有许多IDE在编写时会报告语法错误(例如代码中的错误)。我喜欢Pycharm,但你可以选择你喜欢的任何东西。PyCharm还可以选择转换空格和制表符之间的缩进,这可以帮助您修复代码。
https://stackoverflow.com/questions/34224072
复制相似问题