【发布时间】:2020-04-11 04:22:24
【问题描述】:
我是在 Spyder 上使用 Python 3.7 的初学者程序员,当我运行我的代码时,它会打开一个 system32 命令提示符,然后立即关闭。什么都没发生。当我尝试按下调试按钮时也会发生同样的事情。我将在这里粘贴我的代码。 编辑:感谢 Oliverm,我已经更新了代码,但代码仍然无法启动。
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
#imports
import random
#def the vars
credits = 10
playagain = None
jack = 10
queen = 10
king = 10
ace = 11 #Nice
x = 0
y = 0
a = 0
b = 5
playing = True
cardamount = 0
deck = [1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,jack,jack,jack,jack,queen,queen,queen,queen,king,king,king,king,ace,ace,ace,ace]
#def the functions
def greetings():
print("Greetings! Weclome to Blackjack! d\Do you wish to play?")
print ("Yes or No")
answer = input()
if answer == "Yes" or "yes" or "y" or "Y":
blackjack()
elif answer == "No" or "no" or "n" or "N":
print ("Alright then. Have a good day!")
else:
print("I have no idea what you just said. can you try that again?")
return
def bets():
print ("How much will you bet?")
print ("You have ",credits, " credits")
bet = int(input())
print ("Alright! Lets start!")
pass
def playerplay():
card1 = random.choice(deck)
card2 = random.choice(deck)
#ace logic here. an if statement.
cardlist = [card1, card2]
if card1 == ace and card2 == ace:
pastace = 2
card1 = 1
card2 =11
elif card1 == ace:
pastace = 1
if card2 + 11 > 21:
ace = 1
else:
ace = 11
elif card2 == ace:
pastace = 1
if card1 + 11 > 21:
ace = 1
else:
ace = 11
else:
pastace = 0
pass
cardamount = card1 + card2
print ("You drew a ", card1, " and a ", card2)
while playing == True:
print ("You currently have ", cardamount, " points with ", pastace, "aces" )
print ("Hit or Stand?")
hvalue = str(input())
if hvalue == 'Hit' or "hit" or "H" or "h":
cardlist.append(random.choice(deck))
#calculates cardamount
for y in len(cardlist):
cardamount += cardlist[y]
if y == len(cardlist):
y = 0
break
else:
y += 1
#paste ace logic here
if cardlist[x + 1] == ace:
pastace += 1
if cardamount > 21 and pastace == 1:
ace = 1
cardamount == card1 + card2
for y in len(cardlist):
cardamount += cardlist[y]
if y == len(cardlist):
y = 0
break
else:
y += 1
if cardamount > 21:
print("You have drawn over 21 cards. Now the dealer will play.")
playing = False
del cardlist[0:x]
pcardamount = cardamount
pastace = 0
x = 0
pass
else:
x += 1
return
elif cardamount > 21 and pastace > 1:
ace = 1
cardamount = card1 + card2
for y in len(cardlist):
cardamount += cardlist[y]
if y == len(cardlist):
y = 0
break
else:
y += 1
if cardamount > 21:
print("You have drawn over 21 cards. Now the dealer will play.")
playing = False
del cardlist[0:x]
pastace = 0
pcardamount = cardamount
x = 0
pass
elif cardamount - 22 > -11:
ace in cardlist = 11
return
else:
x += 1
return
else:
x += 1
return
elif hvalue == 'Stand' or 'stand' or 'S' or "s":
print ('Alright! Your total card amount is ', cardamount)
playing = False
del cardlist[0:x]
pastace = 0
pcardamount = cardamount
x = 0
pass
else:
print ("I'm sorry. What did you say?")
return
def outcome():
print("Your total card amount was", pcardamount, "and the dealer's was ", dcardamount)
if pcardamount > dcardamount and pcardamount <= 21 :
print("You win!")
credits += bet*2
elif pcardamount < dcardamount and dcardamount <=21 :
print("You lose...")
credits -= bet
else:
print("It's a tie!")
#says who wins here and defines playagain
playing = True
print("You now have ", credits, " credits.")
print ("Do you wish to play again?")
answer2 = str(input())
if answer2 == "Yes" or "yes" or "y" or "Y":
blackjack()
elif answer2 == "No" or "no" or "n" or "N":
print("Thank you for playing! Have a great day!")
else:
print: ("I have no idea what you just said. can you try that again?")
return
def hit():
cardlist.append(random.choice(deck))
#calculates cardamount
for y in len(cardlist):
cardamount += cardlist[y]
if y == len(cardlist):
y = 0
break
else:
y += 1
#paste ace logic here
if cardlist[x + 1] == ace:
pastace += 1
if cardamount > 21 and pastace == 1:
ace = 1
cardamount == card1 + card2
for y in len(cardlist):
cardamount += cardlist[y]
if y == len(cardlist):
y = 0
break
else:
y += 1
if cardamount > 21:
del cardlist[0:x]
pastace = 0
x = 0
dcardamount = cardamount
cardamount = 0
pass
else:
x += 1
return
elif cardamount > 21 and pastace > 1:
ace = 1
cardamount = card1 + card2
for y in len(cardlist):
cardamount += cardlist[y]
if y == len(cardlist):
y = 0
break
else:
y += 1
if cardamount > 21:
playing = False
del cardlist[0:x]
pastace = 0
x = 0
dcardamount = cardamount
cardamount = 0
pass
elif cardamount - 22 > -11:
ace in cardlist = 11
return
else:
x += 1
return
else:
x += 1
def dealerplay():
card1 = random.choice(deck)
card2 = random.choice(deck)
#ace logic here. an if statement.
cardlist = [card1, card2]
if card1 == ace and card2 == ace:
pastace = 2
card1 == 1
card2 ==11
elif card1 == ace:
pastace = 1
if card2 + 11 > 21:
ace = 1
else:
ace = 11
elif card2 == ace:
pastace = 1
if card1 + 11 > 21:
ace = 1
else:
ace = 11
else:
pastace = 0
pass
cardamount = card1 + card2
if cardamount < 17:
hit()
return
else:
del cardlist[0:x]
pastace = 0
x = 0
dcardamount = cardamount
cardamount = 0
pass
def blackjack():
bets()
playerplay()
dealerplay()
outcome()
#game functions put together
greetings()
【问题讨论】:
-
我正在尝试运行它,以便查看我得到的错误你不知道错误吗?
-
编辑:我在缩进中不再使用不一致的制表符,但现在我收到“语法错误:无法分配给比较”。对于说
ace in cardlist = 11的行 -
那在哪里?你希望这个表达式做什么?
-
它在第 126 行和第 220 行,我希望它只使卡片列表中的第一个 ace 等于 11,而其他 ace 等于 1。
-
那段代码太密集了,我读不下去了。
标签: python python-3.x debugging spyder ipdb