225k views
2 votes
I am writing a Python code to ask a user to enter students' information including name,

last name and student ID number. The program should continue prompting the
user to enter information until the user enters zero. Then the program enters
search mode. In this mode, the user can enter a student ID number to retrieve
the corresponding student's information. If the user enters zero, the program
stops. Please help!​

User Davvs
by
6.2k points

1 Answer

2 votes

Answer:

student_file = {}

endf_input = '1'

for x in iter(list, 1):

name = input("Enter a student name: ")

st_id = int(input("Enter a student id number: "))

student_file[name] = st_id

endf_input = input("Add more student to file (type 1 for yes and 0 to end): ")

if endf_input == '0':

break

print("Search for Student")

search = int(input("Enter student id: "))

if search == 0:

print("Sorry, no student with id of zero.")

quit()

for key, value in student_file.items():

if value == search:

print(f"Student name: {key}")

Step-by-step explanation:

The program source code uses a for loop to continuously add data to the student file dictionary structure but breaks from the loop when a zero is received as input. The program enters search mode and returns the name of the student with the searched id number.

User Emin Mesic
by
7.2k points