Question

(I would like this to be in five parts.) Write a program (Python module) that includes...

(I would like this to be in five parts.) Write a program (Python module) that includes a function named studentrecords. This function must support execution of two loops. The first loop is to query the user whether they wish to enter additional records or not. It must accept responses of either yes or no as input, regardless of the letter-cases used for individual letters in the response. If the response is not recognized ( it isn’t yes or no) it must re-query the user for a valid response. If the response is yes, the loop must prompt the user to enter a student’s first and last names (separately), student ID, grade point average and year of birth. These will be used to create a list of these five pieces of information. This will then be added to a dictionary of student records (the lists for the individual students), with the student ID being the key for the dictionary entries. You may assume valid numeric responses when the user is entering student GPA and year of birth, rather than check those responses. Do not assume that student IDs are numeric. If the response is no, and there are at least two student records, the second main loop is to be executed. This loop will query the user regarding which field to display the student records sorted by. You may prompt the user by asking the user to specify by a decimal digit which to sort by, but you must also list the valid options (digits 1 through 5 are to be used). An additional option indicating no further sorting and displaying is to be done must be provided. If the response is not recognized, the user must be re-queried for a valid response. Given a valid response, you are to quit the function or display the student records in sorted order, low to high, by the specified field.

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

Done accordingly. Comment for further help.Please uprate.

Code:

def getResponse():
response="";
while response!="yes" and response!="no":
response=input("Do you want to continue? (yes/no) ")
response=response.lower()
return response

def readStudent():
firstName=input("Please give first name :")
lastName=input("Please give last name :")
studentId=input("Please give student ID :")
grade=int(input("Please give grades point :"))
yearOfBirth=int(input("Please give year of birth :"))
student=[0,0,0,0,0]
student[1]=firstName
student[2]=lastName
student[0]=studentId
student[3]=grade
student[4]=yearOfBirth
  
return student

def printStudent(student):
print("%7s\t%10s\t%10s\t%5s\t%4s" %(student[0],student[1],student[2],str(student[3]),str(student[4])))

def printAll(students):
print("%7s\t%10s\t%10s\t%5s\t%4s" %("ID","First Name","Last Name","Grade","Year"))
for student in students:
printStudent(students[student])

def getChoice():
choice=int(input("Sorting:\nPlease select.\n1: ID\n2: First Name\n3: Last Name\n4: Grade\n5: Year\n6: To exit\n"))
while choice>6 and choice<0:
choice=int(input("Invalid Input. Please select(1-6)"))
return choice
def main():
studentData={}
response="yes"
while response=="yes":
student=readStudent()
studentData[student[2]]=student
response=getResponse()
  
if(len(studentData)>1):
choice=1
else:
choice=6
  
while choice!=6:
student2={}
for key, value in sorted(studentData.items(), key=lambda e: e[1][choice-1]):
student2[key]=value
printAll(student2)
choice=getChoice()
  
main()

Code Screenshot:

Output:

Add a comment
Know the answer?
Add Answer to:
(I would like this to be in five parts.) Write a program (Python module) that includes...
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 an application that displays a series of at least five student ID numbers (that you...

    Write an application that displays a series of at least five student ID numbers (that you have stored in an array) and asks the user to enter a numeric test score for the student. Create a ScoreException class, and throw a ScoreException for the class if the user does not enter a valid score (less than or equal to 100 or greater than 0). Catch the ScoreException and then prompt the user to re-enter the score. At the end of...

  • using this code to complete. it python 3.#Display Program Purpose print("The program will show how much...

    using this code to complete. it python 3.#Display Program Purpose print("The program will show how much money you will make working a job that gives a inputted percentage increase each year") #Declaration and Initialization of Variables userName = "" #Variable to hold user's name currentYear = 0 #Variable to hold current year input birthYear = 0 #Variable to hold birth year input startingSalary = 0 #Variable to hold starting salary input retirementAge = 0 #Variable to hold retirement age input...

  • In C++, write a complete program that receives a series of student records from the keyboard...

    In C++, write a complete program that receives a series of student records from the keyboard and stores them in three parallel arrays named studentID and courseNumber and grade. All arrays are to be 100 elements. The studentID array is to be of type int and the courseNumber and grade arrays are to be of type string. The program should prompt for the number of records to be entered and then receive user input on how many records are to...

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

  • using java Program: Please read the complete prompt before going into coding. Write a program that...

    using java Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...

  • The application must contain at least these five separate methods. Name them whatever you like. This...

    The application must contain at least these five separate methods. Name them whatever you like. This is functionality they will perform in the application: main method, random number generator method , Initial application display and user input method, Display race information, Display ending information and user continue input. Use the random() method of the java.lang.Math class to generate a random number. The user will enter a response to the initial prompt. The application will generate a random number for a...

  • Python 3.7 to be used. Just a simple design a program that depends on its own. You should also not need to import anythi...

    Python 3.7 to be used. Just a simple design a program that depends on its own. You should also not need to import anything. No code outside of a function! Median List Traversal and Exception Handling Create a menu-driven program that will accept a collection of non-negative integers from the keyboard, calculate the mean and median values and display those values on the screen. Your menu should have 6 options 50% below 50% above Add a number to the list/array...

  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

  • Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_Student...

    Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_StudentlD where StudentID is your actual student ID number) that has one integer input (N) and one double input (x) and returns a double output S, where N S = n 0 and X2 is given by 0 xeVn n 0,1 Хл —{2. nx 2 n 2 2 m2 x2 3 (Note: in the actual quiz, do not expect a always, practice...

  • Write an application that displays a series of at least five student ID numbers (that you...

    Write an application that displays a series of at least five student ID numbers (that you have stored in an array) and asks the user to enter a numeric test score for the student. Create a ScoreException class, and throw a ScoreException for the class if the user does not enter a valid score (less than or equal to 100). Catch the ScoreException, display the message Score over 100, and then store a 0 for the student’s score. At the...

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