Question

In: Computer Science

Create a simple python app that allows the user to create a roster of students and...

Create a simple python app that allows the user to create a roster of students and their grade on CUS-1166.

Moreover the app needs to calculate the average grade of students added to the roster.

1-To begin with, create a new file n the same working folder as part A (i.e. cus1166_lab1) and name it app.py. Moreover, create a subfolder and name it mymodules.

2-Within mymodules create the files __init__.py , models.py , math_utils.py .

3-In the models.py file define a Student class. A Student class need to have two attributes, the student_name and strudent_grade .

4-It also has three methods as follows: set_grade(grade) that sets the grade of the student. get_grade returns the grade of the student. print_student_info that print the name and grade of student in a formated string. In the math_utils.py file define a function called average_grade(roster) .

This method accepts as input a list of Student Objects and returns the average of the current roster. In the app.py file, create a main function, to create a roster of 10 students, print the list of students, and print the average score of the current roster. You can either populate the student roster interactively (i.e. by using the input method to prompt the user from the console) or hard-code the student information in your code. You app.py file must use the Student class, and the average_grade method you defined the mymodules module.

Solutions

Expert Solution

Note: Done accordingly. Please comment for any problem. Please Uprate. Thanks.

Code:

app.py

from mymodules.models import Student
from mymodules.maths_util import average_grade

import random
def main():
roster=[]
for i in range(10):
name="name"+str(i)
grade=random.randint(0,100)
stud=Student(name,grade)
roster.append(stud)
  
for student in roster:
student.print_student_info();
  
print("Average of roster is :"+str(average_grade(roster)))

main()

models.py

class Student(object):
"""
Returns a ```Student``` object with the given name and grade.

"""
def __init__(self, student_name, student_grade):
self.student_name = student_name
self.student_grade = student_grade

def set_grade(self,grade):
self.student_grade = grade
  
def get_grade(self):
return self.student_grade
  
def print_student_info(self):
print("Student Name:"+self.student_name+" and Student grade :"+str(self.student_grade))

maths_util.py

def average_grade(roster):
sum=0
for student in roster:
sum=sum+student.get_grade()
sum=sum/len(roster)
return sum

Output:


Related Solutions

Summary Develop a Spring Boot Web App which allows user to create a list of the...
Summary Develop a Spring Boot Web App which allows user to create a list of the destinations they have visited during vacations. Your application should allow user to search for a destination based on year of visit. Form View The initial page should have links to either search for a destination , add a new destination, display a list of all destinations that they have visited. The search destination page will have a text field to search by year. The...
A start-up firm as developed a new email app that allows the user to decide what...
A start-up firm as developed a new email app that allows the user to decide what mail gets into their mail box. This company doesn't have a lot of start-up capital and they are funded by a Venture Capital firm that wants an expected 18% return. They are going to use the Agile model and release various versions of their app overtime as they see what works. There 3- year start up plan includes: Initial Development Expenses of $100,000 per...
[4 marks] Write a Python program for a “Deliver-Eat!” app that asks the user for their...
[4 marks] Write a Python program for a “Deliver-Eat!” app that asks the user for their tip amount. If the user tips less than $5 they should receive a 1-star rating. If the user tips $5 or more they should receive a 5-star rating. Your program should match the output below. User input is in red. >>> How much would you like to tip? $4.50 >>> Here is your rating! * >>> How much would you like to tip? $7.20...
Write a Flask app in which a Python script prompts the user to enter a string...
Write a Flask app in which a Python script prompts the user to enter a string and then that string, as entered, gets displayed on an otherwise blank HTML file, called output.html. Show the Python/Flask code and the html code of the output.html file, one below the other as part of your answer.
Use Visual Python or equivalent, to write a program that allows the user to observe the...
Use Visual Python or equivalent, to write a program that allows the user to observe the following: Damped and forced harmonic oscillators. The program should be user friendly and have default values for the initial velocities, positions, masses, and spring constants as well as damping constants. Values and frequencies for the forced oscillators should also be given. It should allow the user to input values for the velocities, positions, spring constants, and masses. The program should determine automatically the scale...
9) This is in Python Code a program that allows the user to manage its expenses...
9) This is in Python Code a program that allows the user to manage its expenses accepting the following commands: - Add <player_name> -> This command adds a new player to the system. Assume there can’t be repeated names. If a name already exists then an error is shown to the user. - Score <player_name> <score> -> This command adds the score to the player with the name player-name. Each score needs to be added individually - Report -> This...
Python Add a command to this chapter’s case study program that allows the user to view...
Python Add a command to this chapter’s case study program that allows the user to view the contents of a file in the current working directory. When the command is selected, the program should display a list of filenames and a prompt for the name of the file to be viewed. Be sure to include error recovery in the program. If the user enters a filename that does not exist they should be prompted to enter a filename that does...
Using python, allows a user to enter the values of two, 3x3 matrices and then select...
Using python, allows a user to enter the values of two, 3x3 matrices and then select from options including, addition, subtraction, matrix multiplication, and element by element multiplication. You should use numpy.matmul()for matrix multiplication(e.g. np.matmul(a, b)).The program should computer the appropriate results and return the results, the transpose of the results, the mean of the rows for the results, and the mean of the columns for the results.When entering data you should check that each value is numeric for the...
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT