Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- A program that would accept a set dictionary data
- student: dict={
- 'idno':<inputted data>
- 'name':<inputted data>
- 'course':<inputted data>
- 'level':<inputted data>
- }
- and put it in a list, create a menu that would
- facilitate the operators on the options provided
- Details below:
- ------Main Menu------
- 1. Add Student
- 2. Find Student using idno
- 3. Delete Student using idno
- 4. Display all
- 0. Quit/End
- ---------------------
- Enter Option(0..4):
- """
- from os import system
- student_list: list = []
- def getdata() -> dict:
- system("cls")
- student: dict = {} # empty dictionary, not an empty set
- try:
- idno: int = int(input("Enter id number: "))
- student['idnum'] = idno
- except Exception:
- print("Invalid Age")
- student.setdefault('idnum', 0)
- studentname: str = input("Enter student name: ")
- course: str = input("Enter course: ")
- level: str = input("Enter level: ")
- student['studentname'] = studentname
- student['course'] = course
- student['level'] = level
- return student
- def addstudent() -> None:
- global student_list
- stud: dict = getdata()
- student_list.append(stud)
- def findstudent() -> None:
- idno: int = int(input("Enter id number: "))
- if len(student_list) > 0:
- for student in student_list:
- if student['idnum'] == idno:
- print(student['idnum'], end=' ')
- print(student['studentname'], end=' ')
- print(student['course'], end=' ')
- print(student['level'], end=' ')
- print("")
- break
- else:
- print("List is Empty")
- input("Press any key to continue...")
- def deletestudent() -> None:
- print("----Delete a student from the list----")
- idno: int = int(input("Enter id number: "))
- if len(student_list) > 0:
- for student in student_list:
- if student['idnum'] == idno:
- student_list.remove(student)
- break
- else:
- print('Student did not exist!')
- input("Press any key to continue...")
- def displayall() -> None:
- if len(student_list) > 0:
- for student in student_list:
- print(f"{student['idnum']} {student['studentname']} {student['course']} {student['level']}")
- else:
- print("List is empty !")
- input("Press any key to continue")
- def terminate() -> None:
- print("Program Ends...")
- def menuselect(option: int) -> None:
- mymenu = {
- 1: addstudent,
- 2: findstudent,
- 3: deletestudent,
- 4: displayall,
- 0: terminate
- }
- func = mymenu.get(option)
- return func()
- def menu() -> None:
- system("cls")
- menuitems = (
- '-----Main Menu----',
- '1. Add Student',
- '2. Find Student using idno',
- '3. Delete Student using idno',
- '4. Display All',
- '0. Quit/End ',
- '------------------'
- )
- [print(menuitem) for menuitem in menuitems]
- def main() -> None:
- opt: int = -1
- while opt != 0:
- menu()
- opt = int(input("Enter Option (0..4):"))
- menuselect(opt)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement