如何在Python中的if语句中调用特定的函数?

2024-03-28 18:27:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我对Python是比较新的,在我的基金年,我学习了Basic Basic,这是非常基础的,我在那里养成了很多坏习惯。 我在codecademy的帮助下学习了python,但是,如何在if语句中调用函数呢?然而,在我的第一个if语句中,我调用了函数mainMenu(menu),它没有显示函数内容。为什么?

(顺便说一句,我只是想做一台自动取款机,只是为了练习我学到的一些东西并巩固它

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 "------------------------------------------------"

Tags: to函数inputrawifbasicis语句