为什么我未完成的二十一点游戏出现语法错误

我试图制作一个二十一点游戏,但这里有两个语法错误阻止这样做:


(第21、22、23、24行的错误都是语法错误)


(deste = 甲板,desteo = 玩家甲板,desteb = 计算机甲板,pas = 通过)


import random

deste=[10,10,10,10,9,8,7,6,5,4,3,2,1,

       10,10,10,10,9,8,7,6,5,4,3,2,1,

       10,10,10,10,9,8,7,6,5,4,3,2,1,

       10,10,10,10,9,8,7,6,5,4,3,2,1]

desteo=[]

desteb=[]

pas=3

oyunbitti=0

desteo.append(random.choice(deste))

deste.remove(desteo[-1])

desteb.append(random.choice(deste))

deste.remove(desteb[-1])

def hamle():

    print("Destenin değeri : ",sum(desteo))

    print("Bilgisayar destesinin değeri : ",sum(desteb))

    print("Kalan pas hakkın: ",pas)

    yanit=input("Hamleni yap:\n1 Kart al\n2 Pas geç\n")

    if yanit==1:{

    desteo.append(random.choice(deste)

    deste.remove(desteo[-1]) 

        if sum(desteo)>21:{

            oyunbitti=1}}

print("test")


扬帆大鱼
浏览 127回答 1
1回答

慕尼黑5688855

除非我遗漏了什么,否则 Python 使用缩进来表示作用域而不是大括号 ( {})。修复这个问题,以及一些奇怪的缩进,test如果这就是你想要的,它会打印“”import randomdeste=[10,10,10,10,9,8,7,6,5,4,3,2,1,       10,10,10,10,9,8,7,6,5,4,3,2,1,       10,10,10,10,9,8,7,6,5,4,3,2,1,       10,10,10,10,9,8,7,6,5,4,3,2,1]desteo=[]desteb=[]pas=3oyunbitti=0desteo.append(random.choice(deste))deste.remove(desteo[-1])desteb.append(random.choice(deste))deste.remove(desteb[-1])def hamle():    print("Destenin değeri : ",sum(desteo))    print("Bilgisayar destesinin değeri : ",sum(desteb))    print("Kalan pas hakkın: ",pas)    yanit=input("Hamleni yap:\n1 Kart al\n2 Pas geç\n")    if yanit==1: # don't use curly braces        desteo.append(random.choice(deste)) # these have been indented        deste.remove(desteo[-1])         if sum(desteo)>21: # no curly braces here either            oyunbitti=1print("test")
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python