import random
gCount = 1
pChoice = ("sdq")
while gCount == 10 or pChoice == ("q"):
pChoice = input("Steal, Deal or Quit [s|d|q]?")
if pChoice != ("q"):
gCount += 1
print("Jackpot:100")
#Determing and displaying choice
if pChoice == ("s"):
print("C: Steal")
elif pChoice == ("d"):
print ("C: Deal")
#Determing and displaying computer choice
cChoice= random.randint(1,2)
if cChoice == 1:
print("Comp:Steal")
elif cChoice == 2:
print("Comp:Deal")
#Determining and displaying whether the player wins or loses, as well as scores
# for that round.
if pChoice == ("s") and cChoice == 1:
print("S: 0 | 0")
print("You lose! You get nothing!")
elif pChoice == ("d") and cChoice == 1:
print("S: 0 | 100")
print("You lose! You get nothing!")
elif pChoice == ("d") and cChoice == 2:
print("S: 50 | 50")
print("Draw! Split pot!")
else:
print("S: 100 | 0")
print("You win! Jackpot!")
此代码正在返回
================================ RESTART ================================
在IDLE终端中运行时。我不确定导致这种情况的原因。
Python 3.4.3
32-bit IDLE for 3.4.3
Windows 7 64-bit
答案 0 :(得分:5)
假设代码的缩进是这样的(否则会出现语法错误):
import random
gCount = 1
pChoice = ("sdq")
while gCount == 10 or pChoice == ("q"):
# everything else here
然后你的脚本什么都不做。 gCount
为1
,因此gCount == 10
将永远不会为真,因此循环中没有任何内容会运行,否则就没有输出。
所以RESTART
行只是说IDLE解释器重置自己,然后运行你的脚本(导致没有输出),然后就结束了。