2013-06-29 37 views
0

我有一個骰子滾輪程序問題(現在的文本,但最終圖形)。它不會在除了我使用的IDE之外的任何工作,Wing IDE 101 4.1。我得到的錯誤閃爍太快,無法閱讀,但我會嘗試截取它。 (如果我得到的截圖,我會編輯這個職位。)爲什麼這個程序不能在shell中工作,但在我的IDE中工作?

下面是程序:

import random 


#variables 

available_dice = "D20" 
main_pgm_start = False 

#definitions of functions 

def diePick(): 
    print("Pick a die. Your choices are: ", available_dice) 
    print("") 
    which_dice = input("") 

    if which_dice == "D20" or which_dice == "d20": 
     rollD20()  
    else: 
     print("Error: Please try again") 
     print("") 
     diePick()  

def rollD20(): 
    print("Rolling D20 .... ") 
    print("") 
    d20_result = random.randrange(1, 20) 
    print("You have rolled a ", d20_result) 
    print("") 
    print("Would you like to roll again?") 
    print("") 
    y = input("") 
    if y == "y" or y == "Y" or y == "yes" or y == "Yes": 
     print("")   
     diePick() 



def MainProgram(): 
    print("Benjamin Ward's Random D&D Dice Roller") 
    print("") 
    x = input(" Press Enter to Continue") 
    print("") 
    diePick() 


MainProgram() 
+0

你正在使用哪個python版本? – mata

+0

@mata即時通訊使用Python版本3.2,虐待添加到標籤 – Pip

+0

您是否收到任何錯誤消息?你確定從終端開始的python interperter也是python3而不是python2嗎? – mata

回答

1

如果我的記憶服務,您可以使用「記錄」模塊將日誌重定向到文本文件。

-1

我不認爲輸入()做你希望它是什麼。輸入讀取一行文本,然後執行它(作爲python)。

我想你想要的更多的是沿着stdin.readline()的路線。要使用它,您必須在頂部from sys import stdin,然後用sys.readline()替換input的所有出現。還要注意,這將在最後返回一個換行符,您必須考慮這個換行符。

+0

是的。我知道。即時通訊使用作爲佔位符,所以我不必使用getch(),我正在考慮。此外,它不執行它。它將它存儲在變量 – Pip

+0

OP正在使用python3,所以你錯了,輸入只是讀取一行文本。 – mata

+0

我猜這是Python 3.x,在這種情況下'輸入'沒有評估。 – Tim

相關問題