當我運行代碼時,我的while循環完美地工作,然後程序就結束了,即使我有一個我想要運行的其他函數。 在以login = False結尾的這段代碼之前有一段while循環,我也嘗試用break來代替它,並且發生同樣的事情。python-當我運行我的函數時沒有任何事情發生
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文件到你已經做到了回到學校菜單,然後經過什麼。然而,整個功能根本沒有運行。爲什麼?
重新安排你的代碼,請 –
重新安排它以何種方式,你想? – user8549523
您的縮進看起來很混亂。 –