2012-11-10 94 views
0

我是python的新手,這是我第一個真正的程序。 繼承人的代碼:代碼在Python shell中工作,但沒有命令提示符

def home(): 
    print ('game....play-1..options-2..rules-3..exit-4..') 
    answer = input() 
    print(repr(answer)) 
    if answer == '1': 
     play() 
    elif answer == '2': 
     options() 
    elif answer == '3': 
     rules() 
    elif answer == '4': 
     end() 


def rules(): 
    print ('rules...main menu-1...exit-2..') 
    answerRules = input() 
    print(repr(answerRules))  
    if answerRules == '1': 
     home() 
    elif answerRules == '2': 
     end() 

home() 

主要的問題我來到這裏是它的工作原理在Python外殼罰款,但不帶命令提示符。然而,在命令提示符home()中,只要您輸入答案,例如3.該計劃剛剛結束。

+0

蟒蛇什麼版本的?如果2.x,輸入將返回一個int,而不是一個字符串 –

+0

我認爲你應該提及你使用的操作系統。 – SaidbakR

+2

適用於我的系統。 Win7_64 + python 3.0.1(2位)。 請提及您的操作系統和python版本。 – anishsane

回答

0

答案是int

類型,以便與if answer == 1:
檢查將解決

+0

我認爲'print()'函數表明OP在'python3.x'上,所以'input()'在這種情況下不是int。 –

+0

感謝您的快速反應,它的工作:) –

+0

@OliverBennett你在Python 2.x? –

0

您應該檢查input()是否從命令提示符運行時返回回車符或其他字符。

相關問題