我相对较新的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他必须将功能移到顶部,否则它不会被检测到。 –