In: Computer Science
You will need the following variables:
ExamAvg, FinalExam, Partication, AssignAvg, MyName, Grade
Create lists for Exams and Assignments, ExamList and AssignList.
Assume Participation is 100% for now and assign values to assignments and exams (you'll have to guess at Exam2). Use methods we have learned on lists to calculate the averages.
Your grade is calculated by the following weighting formula:
Grade = (0.30)*(ExamAvg) + (0.25)*FinalExam + (0.05)*Participation + (0.40)*AssignAvg
Use a series of if-else, and elif statements to calculate (and print) your grade according to the following:
if 90 <= grade <= 100 Congratulations, MyName, you earned an A.
if 80 <= grade <= 89 Good work, MyName, you earned a B.
if 70 <= grade <= 79 You earned a C, MyName, perhaps a bit more work?
if 60 <= grade <= 69 You earned a D, MyName, come for help if you need it.
if grade < 60 You are failing the course. Please come for help.
You are free to use different variable names, put values in a list, etc.
Our task is to find the apropriate grade according to the score we obatined by the given equation,
Grade = (0.30)*(E-xamAvg) + (0.25)*FinalE-xam + (0.05)*Participation + (0.40)*AssignAvg
To do that we need to create two list (E-xam and assignment) and initialize them with values then find avarage avg odf e-xam and assignment and assign it to apropriate variables
Lets see how to code this in python,
Code
(Please raed all comments for the better understanding of the program)
Sample Run
I am also providing the text version of the code in case you need to copy paste
E-xam=[87,95,67,83,75,78,94] #Initialization of list E-xam
Assignment=[65,95,96,90,87,99] #Initialization of list Assignment
FinalE-xam=95 #final e-xam score is initialized as 95
Myname='DiCaprio' #Myname is set
Participation=100
sum=0 #setting sum to zero to fing average
for i in E-xam: #iterating through each element in the list
sum=sum+i #finding sum
E-xamAvg=sum/len(E-xam) #finding average (len()is used to find the
length of list)
sum=0
for i in Assignment:
sum=sum+i
AssignAvg=sum/len(Assignment) #finding average of assignment
grade=
(0.30*E-xamAvg)+(0.25*FinalE-xam)+(0.05*Participation)+(0.40*AssignAvg)
#grade finding formula
grade=int(grade) #rounding the grade
if grade>=90 and grade<=100: # if -else ladder to find the
apropriate grade
print('Congatulations ',Myname,' You earned an A')
elif grade>=80 and grade<=89:
print('Good work ',Myname,' You earned a B')
if grade>=70 and grade<=79:
print('You earned a C ',Myname,' perhaps a bit more work?')
if grade>=60 and grade<=69:
print('You Earned a D ',Myname,' come for help if you need
it')
elif grade <60 :
print('you are failing the course,Please come for help.')