当使用用户名和密码运行代码登录到系统时,我会得到错误'secret' is not defined
,如何让它停止这样说并正常运行?你知道吗
这是错误消息:
Traceback (most recent call last): File "C:\Users\Samuel\Documents\School\Computing\NEA - H\Program.py", line 16, in while username != secret: NameError: name 'secret' is not defined
代码如下:
from random import randint
import os
import time
import sys
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
username = ""
while username != secret:
username = input("Please enter the username: ")
if username == secret:
print("Thank you. You have entered the correct username")
else:
print("Sorry the value entered in incorrect - try again")
password = ""
while password != password:
password = input("Please enter the password: ")
if password == password:
print("Thank you. You have entered the correct password, You are now in the menu system")
else:
print("Sorry the value entered in incorrect - try again")
def online():
time.sleep(1)
print("Welcome Teacher")
logIn()
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
def addStudent():
print("Loading student creator...")
time.sleep(1)
studentFile = open("Student_Details.txt","w")
ID = randint(1,1000)
surname = input("Surname: ")
time.sleep(1)
forename = input("Forename: ")
time.sleep(1)
DOB = input("Date of Birth: ")
time.sleep(1)
age = input("Age: ")
time.sleep(1)
homeAddress = input("Home address: ")
time.sleep(1)
homePhone = input("Home phone number: ")
time.sleep(1)
gender = input("Gender: ")
time.sleep(1)
tutor = randint(1,48)
time.sleep(1)
print("Writing to 'Student details.txt' now")
time.sleep(1.5)
email = (forename + surname + str(ID) + "@treeroadschool.net")
studentFile.write(str(ID) + "\n")
studentFile.write(surname + "\n")
studentFile.write(forename + "\n")
studentFile.write(str(DOB) + "\n")
studentFile.write(str(age) + "\n")
studentFile.write(homeAddress + "\n")
studentFile.write(homePhone + "\n")
studentFile.write(gender + "\n")
studentFile.write(str(tutor) + "\n")
studentFile.write(email + "\n")
studentFile.close()
print("Student data stored")
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
def logOut():
print("Logging out...")
sys.exit()
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
def viewStudent():
print("MENU")
print("Choose one of the students by their number:")
print("><><><><><><><><><><><><><><><><><><><><><")
time.sleep(1)
print("1-25")
time.sleep(1)
choice2 = int(input("Choice? "))
print("><><><><><><><><><><><><><><><><><><><><><")
time.sleep(1)
if choice2 == 1:
studentFile1 = open('Student_Details_01.txt', 'r')
print (studentFile1.readlines())
elif choice2 == 2:
studentFile2 = open('Student_Details_02.txt', 'r')
print (studentFile2.readlines())
elif choice2 == 3:
studentFile3 = open('Student_Details_03.txt', 'r')
print (studentFile3.readlines())
elif choice2 == 4:
studentFile4 = open('Student_Details_04.txt', 'r')
print (studentFile4.readlines())
elif choice2 == 5:
studentFile5 = open('Student_Details_05.txt', 'r')
print (studentFile5.readlines())
elif choice2 == 6:
studentFile6 = open('Student_Details_06.txt', 'r')
print (studentFile6.readlines())
elif choice2 == 7:
studentFile7 = open('Student_Details_07.txt', 'r')
print (studentFile7.readlines())
elif choice2 == 8:
studentFile8 = open('Student_Details_08.txt', 'r')
print (studentFile8.readlines())
elif choice2 == 9:
studentFile9 = open('Student_Details_09.txt', 'r')
print (studentFile9.readlines())
elif choice2 == 10:
studentFile10 = open('Student_Details_10.txt', 'r')
print (studentFile10.readlines())
elif choice2 == 11:
studentFile11 = open('Student_Details_11.txt', 'r')
print (studentFile11.readlines())
elif choice2 == 12:
studentFile12 = open('Student_Details_12.txt', 'r')
print (studentFile12.readlines())
elif choice2 == 13:
studentFile13 = open('Student_Details_13.txt', 'r')
print (studentFile13.readlines())
elif choice2 == 14:
studentFile14 = open('Student_Details_14.txt', 'r')
print (studentFile14.readlines())
elif choice2 == 15:
studentFile15 = open('Student_Details_15.txt', 'r')
print (studentFile15.readlines())
elif choice2 == 16:
studentFile16 = open('Student_Details_16.txt', 'r')
print (studentFile16.readlines())
elif choice2 == 17:
studentFile17 = open('Student_Details_17.txt', 'r')
print (studentFile17.readlines())
elif choice2 == 18:
studentFile18 = open('Student_Details_18.txt', 'r')
print (studentFile18.readlines())
elif choice2 == 19:
studentFile19 = open('Student_Details_19.txt', 'r')
print (studentFile19.readlines())
elif choice2 == 20:
studentFile20 = open('Student_Details_20.txt', 'r')
print (studentFile20.readlines())
elif choice2 == 21:
studentFile21 = open('Student_Details_21.txt', 'r')
print (studentFile21.readlines())
elif choice2 == 22:
studentFile22 = open('Student_Details_22.txt', 'r')
print (studentFile22.readlines())
elif choice2 == 23:
studentFile23 = open('Student_Details_23.txt', 'r')
print (studentFile23.readlines())
elif choice2 == 24:
studentFile24 = open('Student_Details_24.txt', 'r')
print (studentFile24.readlines())
elif choice2 == 25:
studentFile25 = open('Student_Details_25.txt', 'r')
print (studentFile25.readlines())
else:
sys.exit()
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
def viewReport():
print("Loading Report...")
time.sleep(1)
studentFileReport = open('Student_Details_Report.txt', 'r')
print (studentFileReport.readlines())
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
time.sleep(1)
print("><><><><><><><><><><><><><><><><><><><><><")
print("MENU")
print("Choose one of the options by their number:")
print("><><><><><><><><><><><><><><><><><><><><><")
time.sleep(1)
print("1: Add student")
print("2: Log out")
print("3: View student")
print("4: View report")
time.sleep(1)
choice = int(input("Choice? "))
print("><><><><><><><><><><><><><><><><><><><><><")
time.sleep(1)
if choice == 1:
addStudent()
elif choice == 2:
logOut()
elif choice == 3:
viewStudent()
elif choice == 4:
viewReport()
else:
sys.exit()
目前没有回答
相关问题 更多 >
编程相关推荐