我相對較新的python,在我的基礎一年,我學到了BBC BASIC,這很基礎,我在那裏得到了很多壞習慣。 我在codecademy的幫助下學習了python,但是,如何在if語句中調用函數?在我的第一條if語句中,我調用了函數mainMenu(menu)
,但是它沒有顯示函數內容。爲什麼?如何在Python中的if語句中調用某個函數?
(通過我只是試圖做一個ATM機只是練習一些我學到的東西,並鞏固其
print "Hello ! Welcome to JD's bank"
print
print "Insert bank card and press any key to procede"
print
raw_input()
passcode = 1111
attempts = 0
while passcode == 1111:
passcodeInsertion= raw_input("Please insert your 4-digit code: ")
print""
if passcodeInsertion == str(passcode):
print "This is working" #testing-----
print ""
mainMenu(menu)
elif attempts < 2:
print "Sorry ! Wrong passcode"
attempts += 1
print "------------------------------------------------"
print ""
print"Try again !! This is your " + str(attempts) + " attempt"
print
print "------------------------------------------------"
print
else:
print""
print "Your card is unfortunately now blocked"
exit()
def mainMenu(menu):
print "------------------------------------------------"
print "Select one of this options"
print "1. Check Balance"
print "2. Withdraw Money"
print "3. Deposit Money "
print "0. Exit "
print "------------------------------------------------"
'mainMenu(menu)'那麼,你沒有在任何地方定義菜單,所以這將會崩潰。除此之外,不應該有任何問題。 –
@MorganThrapp他必須將功能移到頂部,否則它不會被檢測到。 –