Need to be done in python Define a \"student\" class. A student has a name, a mi
ID: 3575903 • Letter: N
Question
Need to be done in python
Define a "student" class.
A student has a name, a midterm grade and a final grade.
Ask the user to enter the number of students attending the lecture. Then ask the user to enter the properties of the students.
The semester grade of a student is found by the formula: semgrade=(0.4)*(midterm)+(0.6)*(final) and a student whose semgrade is greater than 65 can pass the course.
Write the names of the students who passed the course.
Hint: You can define a "stu" vector which has elements of the type "student" as stu=[student for i in range(N)] and use it in a loop as stu[i]=student(name,midterm,final)
Explanation / Answer
#ashishkr004
class student:
def __init__(self,name,midtermGrade,finalGrade): #take a argument name, midtermGrade and finalGrade
self.name=name
self.midtermGrade=midtermGrade
self.finalGrade=finalGrade
self.semGrade=(0.4*midtermGrade)+(0.6*finalGrade)
print("Enter the number of students attending the lecture: ")
totalStudents=input() #for integer input use input()
stu=[] #create a list stu
t=0
while t<totalStudents: #while t is less than totalStudents
print("Enter Student Name: ")
studentName=raw_input() #for string input use raw_input()
print("Enter Midterm Grade: ")
tMidtermGrade=input()
print("Enter Final Grade: ")
tFinalGrade=input()
stu.append(student(studentName,tMidtermGrade,tFinalGrade))
t=t+1 #increment of t by 1
pass
t=0
while t<totalStudents: #while t is less than totalStudents
if stu[t].semGrade>65: #if student at index t has semGrade greater than 65 print
print(stu[t].name)
pass
t=t+1
pass
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.