Question

In python, Implement a function studentID() which allows the user to enter the 7-digit student ID....

In python, Implement a function studentID() which allows the user to enter the 7-digit student ID. The program will keep prompting the user for a last name and first name. If the student does not have a student ID on record, the program will then ask for the student ID, and store that information. If the student already has a student ID, the program will display it, and ask for confirmation whether a new studentID should be assigned (and, if so allows the new studentID to be entered). When the user hits the return key, the program prints a report listing all students with their studentID. Your report does not have to be in alphabetical order, however, if you do want to make it alphabetical, you can use sorted on the keys of your dictionary.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

'''
Python version : 3.6
Python program to input and store the student name and id
and once the user has finished entering the names and ids, display
the report containing the student names and ids
'''

# function to input and return the student id from user
def studentID():
  
   id = input('Enter the student ID : ')
   return id
  
# main function  
def main():
   # create a dictionary of students where keys are student first and last name and values are student id
   students = {}
  
   # loop that continues till the user wants
   while True:
       # input the first and last name from user
       name = input('Enter lastname and firstname (input <empty string> to quit) : ')
       # check if user wants to quit
       if len(name) == 0:
           break
       # check if name is already present in dictionary  
       if name in students:
           # if present, ask user if they want to generate a new studentID
           print('Student ID for %s is %s '%(name, students[name]))
           choice = input('Do you want to generate a new student ID (y/n) ? ')
          
           # input a new studentID if the user wants
           if choice.upper() == 'Y':
              
               id = studentID()
               # update the studentID in dictionary
               students[name] = id
              
       else: # if name is not present
           id = studentID() # input the studentID
           # add the student name and id in dictionary
           students[name] = id

   # after loop ends, display the student names and studentID  
   print('%-20s%-15s' %('Name','Student ID'))  
   for name in students:
       print('%-20s%-15s' %(name,students[name]))

# call the main function      
main()      
#end of program

Code Screenshot:

Output:

Add a comment
Know the answer?
Add Answer to:
In python, Implement a function studentID() which allows the user to enter the 7-digit student ID....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a "PYTHON" program to prompt the user to enter a fist name, last name, student...

    Write a "PYTHON" program to prompt the user to enter a fist name, last name, student ID and GPA. Create a dictionary with the data. Print out the data. Then remove the GPA and print again.

  • PYTHON PROGRAMMING Instructions: You are responsible for writing a program that allows a user to do...

    PYTHON PROGRAMMING Instructions: You are responsible for writing a program that allows a user to do one of five things at a time: 1. Add students to database. • There should be no duplicate students. If student already exists, do not add the data again; print a message informing student already exists in database. • Enter name, age, and address. 2. Search for students in the database by name. • User enters student name to search • Show student name,...

  • We will build one Python application via which users can perform various analytics tasks on data...

    We will build one Python application via which users can perform various analytics tasks on data in 2-D table (similar to Spreadsheet) format which looks like: Column Name 1 Column Name 2 Column Name 3 Column Name N … … … … … In this table, each row represents the data of one object that we are interested in. Columns, on the other hand, represent the attributes of these objects. For example, this table could represent students’ academic records. Each...

  • This is Python The program should accept input from the user as either 7-digit phone number...

    This is Python The program should accept input from the user as either 7-digit phone number or 10-digit. If the user enters 7 characters, the program should automatically add "512" to the beginning of the phone number as the default area code. Dash (hyphen) characters do not count in input character count, but must not be random. If the user enters dashes the total character count must not exceed 12. The program should not crash if the user enters invalid...

  • NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions...

    NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions Work with files Overview This lab will have you store the birthdays for a group of people. This program will store the information with the focus on the date of the month and not on the individual. The point of this program is to be able to see who has a birthday on a given day or to create a table of birthdays, in...

  • NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions...

    NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions Work with files Overview This lab will have you store the birthdays for a group of people. This program will store the information with the focus on the date of the month and not on the individual. The point of this program is to be able to see who has a birthday on a given day or to create a table of birthdays, in...

  • Topics: list, file input/output (Python) You will write a program that allows the user to read...

    Topics: list, file input/output (Python) You will write a program that allows the user to read grade data from a text file, view computed statistical values based on the data, and to save the computed statistics to a text file. You will use a list to store the data read in, and for computing the statistics. You must use functions. The data: The user has the option to load a data file. The data consists of integer values representing student...

  • Implement a software program in C++ t stores and searches the Student records using double-hashing algorithm.  Double...

    Implement a software program in C++ t stores and searches the Student records using double-hashing algorithm.  Double hashing uses the idea of applying a second hash function to key when a collision occurs.   The software program will be based on the following requirements: Development Environment: If the software program is written in C++, its project must be created using Microsoft Visual Studio 2017. If the software program is written in Java, its project must be created using NetBeans v8.2. Algorithm: If...

  • c++ implement a student class Determine the final scores, letter grades, and rankings of all students...

    c++ implement a student class Determine the final scores, letter grades, and rankings of all students in a course. All records of the course will be stored in an input file, and a record of each student will include the first name, id, five quiz scores, two exam scores, and one final exam score. For this project, you will develop a program named cpp to determine the final scores, letter grades, and rankings of all students in a course. All...

  • Java: student directory GUI You need to implement three classes: Person Student StudentDirectory StudentMain Start by...

    Java: student directory GUI You need to implement three classes: Person Student StudentDirectory StudentMain Start by implementing Person and Student classes. Once you are sure you can serialize and deserialize and ArrayList of Students to and from a file, move on to building the GUI application. Person: The Person class should implement serializable interface. It contains the following: Person's first name (String) Person's last name (String) Person's id number Person's date of birth (Date) public String toString(): This method method...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT