python-当我运行我的函数时什么也没发生

时间:2017-09-01 20:23:08

标签: python function

当我运行代码时,我的while循环工作完美,然后程序就结束了,即使我有一个我想要运行的其他函数。 在这段代码之前有一个while循环,以login = False结束,我也尝试用break替换它,同样的事情发生了。

  import csv
  import sys

username="Leeman"
password="treeroad"

login = True
login_u = input("Enter username ")
login_p = input("Enter password ")

while login == True:

if login_u + login_p != username + password:
        print("incorrect login")
        sys.exit()
elif login_u != username:
        print("incorrect login")
        sys.exit()
elif login_p != password:
        print ("incorrect login")
        sys.exit()
elif login_u + login_p == username + password:
        print("Welcome to the system")
        login = False    

def main_menu():

print("---------------------------------School Menu-----------------------------------")
option=input("""Options:
                    1-Enter new student details
                    2-Search for student by ID number
                    3-View student details
                    4-Reports
                    5-Logout
                    Where do you want to go, 1,2,3,4 or 5?
                    """)

if option == "1":
   details=input("Enter your new student's details in format:ID Number,Forename,Surname,Gender,Tutor Group,DOB(dd/mm/yyyy),Phone Number,School Email: ")
   appendfile=open('classinfo.csv ' , 'a')
   appendfile.write(details)
   appendfile.close
   main_menu()

elif option=='2':
    with open ('classinfo.csv' , 'r') as classinfoFile:
        idnumber = input("Input the ID number of the student you wish to view")
        classinfoReader = csv.reader(classinfoFile)
        for row in classinfoReader:
            for field in row:
                if field == idnumber:
                   print (row)
                   main_menu()

此代码的目的是通过选择一个数字(1-5)来选择要对csv文件执行的操作,然后在完成后再返回学校菜单。然而,整个功能根本就没有运行。为什么?

1 个答案:

答案 0 :(得分:0)

def do_one():
    print("You entered 1!")

def do_two():
    print("You entered 2!")

def main():
    while True:
        choice = int(input("Enter 1, 2, or 3 (to exit): "))
        if choice == 1:
            do_one()
        elif choice == 2:
            do_two()
        elif choice == 3:
            print("Goodbye!")
            break

main()
相关问题