2015-04-29 28 views
-1
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!") 

在IDLE終端中運行時,該代碼被返回IDLE被返回 '=== RESTART ===' 線,但沒有其他輸出

================================ RESTART ================================ 

。我不確定是什麼導致了這一點。

Python 3.4.3 
32-bit IDLE for 3.4.3 
Windows 7 64-bit 
+0

從字面上看,它只是在返回RESTART之前或之後沒有任何東西嗎? – SuperBiasedMan

+4

這是你的確切實際代碼?在你的第一個'while'之後,你的行上有一個縮進錯誤。 – Kevin

+1

如何在IDLE中運行腳本? – poke

回答

5

假設你的代碼的縮進是這樣的(否則這將是一個語法錯誤):

import random 
gCount = 1 
pChoice = ("sdq") 
while gCount == 10 or pChoice == ("q"): 
    # everything else here 

然後你的腳本不會完全沒有。 gCount1,因此gCount == 10永遠不會成立,因爲循環中沒有任何內容會運行,否則就沒有輸出。

因此,RESTART行只是說,IDLE解釋器重置自身,然後運行您的腳本(導致沒有輸出),然後它結束。

+1

你打敗了我。代碼從不進入循環,因爲'(「sdq」)==(「q」)'也是'False'。 –

+0

哎呦,我是個白癡:)。它應該是'pChoice!=「q」' –

相關問題