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

How to do this in Python (using Lists): Create a python program that allows a user...
How to do this in Python (using Lists): Create a python program that allows a user to display, sort and update as needed a List of U.S States containing the State Capital and State Bird. You will need to embed the State data into your Python code. The user interface will allow the user to perform the following functions: 1. Display all U.S. States in Alphabetical order along with Capital and Bird 2. Search for a specific state and display...
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...
Create a Python program that: Allows the user to enter a phrase or sentence. The program...
Create a Python program that: Allows the user to enter a phrase or sentence. The program should then take the phrase or sentence entered Separate out the individual words entered Each individual word should then be added to a list After all of the words have been place in a list Sort the contents of the list Display the contents of the sorted list with each individual word displayed on a separate line Display a message to the user indicating...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will first enter a password, then enters the same password again; If the second input is the same as first one, the user successfully creates the password. Print “Well done.”; Otherwise, the user will be directed to repeat the whole process (go to step 1.)
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.
Create an application that allows the user to enter the total for an order and the...
Create an application that allows the user to enter the total for an order and the name of the customer. If the order is less than 500 dollars, the customer gets no discount. If the order is greater than or equal to 500 and less than 1000 dollars, the customer gets a 5 percent discount. If the order is greater than or equal to 1000 dollars, the customer gets a 10 percent discount. The application should display the name of...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT