58.0k views
0 votes
Write a program that will create a student database using a dictionary. The database will store studentid and name. The studentid will be the key and the name will be the value for the dictionary. The text file will have the studentid and student name, which are separated by a comma(,). The program will read the file and populate the dictionary. The studentid will be the key and the name will be the value. The program will ask the user to enter a studentid. It will search the dictionary. If found, it will display the name; otherwise, it will say 'student not found'. The program will continue until 'n' is entered. Sample: a007, Ally Baba b123, He Man a123, Super Man c234, Spider Man. Note: The project must use functions. The following functions need to be used in your project. If you like, add more functions, it will be great. ⋅ getstringdata() – a function that will validate the user's entry of a non-empty string and return 'y' or 'n'. Return the upper case of 'y' or 'n' ⋅ readdata() – a function that will read the file and store the data in a dictionary ⋅ main() ⋅ displayresult() – will display the required output

User JoAMoS
by
6.9k points

1 Answer

2 votes

Final answer:

To create a student database using a dictionary in Python, follow these steps: create an empty dictionary, read the data from a text file and store it in the dictionary, validate user input, and search the dictionary for a student ID.

Step-by-step explanation:

To create a student database using a dictionary in Python, you can follow these steps:

  1. Create an empty dictionary to store the student information.
  2. Read the data from the text file, split each line by the comma, and store the student ID as the key and the name as the value in the dictionary.
  3. Create a function to validate the user's input and return either 'y' or 'n'.
  4. Create a function to read the file and populate the dictionary with the student data.
  5. Within the main function, use a while loop to continuously prompt the user for a student ID.
  6. Search the dictionary using the entered student ID and display the corresponding name if found, or print 'student not found' if not found.
  7. Keep repeating until the user enters 'n'.
  8. Create a function to display the required output.

User Xirux Nefer
by
7.8k points