私はこのプログラムを持っており、各メニューオプションを実行したいと思います。基本的にユーザーがログインすると、メニューが表示され、1つを押すと機能します。しかし、私が2を押すと、「学生の検索は定義されていません」と伝えられます。私はそれが何を話しているのか分かりません。プログラム内で関数を移動しようとしましたが、それを行うと他のエラーが発生します。私はこれを構造化する正しい方法が何かを探しています。メニューの前に機能がありますか?ログイン後?どのように私はそれらを呼び出すことができますか?NameError:name ''が定義されていません
choice = input
def PrintMenu():
print("\n*******************")
print("\n School menu system")
print("\n*******************")
print(" [1] Add Student")
print(" [2] Search Student")
print(" [3] Find Report")
print(" [4] Exit")
choice = input ("Enter a choice: ")
#while choice =='':
if choice == '1':
AddStudent()
elif choice == '2':
SearchStudent(ID)
elif choice == '3':
FindReport()
elif choice == '4':
print("\nExiting the system......\n")
sys.exit(0)
else:
print ("\n not valid choice")
PrintMenu()
def SearchStudent(ID):
with open("Students.txt", 'r') as file:
for i in file:
data = i.rstrip().split(",")
if data[0] == ID:
return "The student you require is: {} {}".format(data[2], data[1])
return "No matches found"
search = input("Please enter a student ID: ")
print(SearchStudent(search))
私は理解していません行く。メニューの前にログイン機能があり、addstudent機能があり、メニューの前後に置いてみましたが、それでも同じエラーが表示されます。 – CV9
@cᴏʟᴅsᴘᴇᴇᴅどのようなアイデアですか?または提案? – CV9
さらなる助けを借りて答えを更新しました。 –