 |  |

 |
 |  |  |
 | Welcome to CS1315. Click on the python to add comments.
|  |
 |  |  |
|
This page removed for FERPA compliance
|
        |
Midterm Exam 1 Review Spring 2004: Compute the grade
(Return to Sp2004 Midterm 1 Review)
Questions, answers, comments on answers, comments on questions?
def finalgrade(x1,x2,x3):
exam1=(x1*.2)
exam2=(x2*.2)
exam3=(x3*.6)
grandtotal=(exam1+exam2+exam3)
if(grandtotal=>90):
print"Congratulations, you got an A!"
if(grandtotal>=80andgrandtotal<90):
print"You got a B."
if(grandtotal>=70andgrandtotal<80):
print"You got a C."
if(grandtotal>=60andgrandtotal<70):
print"You got a D."
if(grandtotal<60):
print"Better luck next time."
could someone tell me why I keep getting a syntax error in line 6?
Student1054
Amelia Cipolla
def finalGrade(exam1, exam2, exam3):
value1=(0.4*((exam1+exam2)/2))
value2=(0.6*exam3)
finalGrade=(value1+value2)
if fianlGrade>89:
print "Congradulations, you got an A!"
if finalGrade>79 and <90:
print "You got a B."
if finalGrade>69 and <80:
print "you got a C."
if finalGrade>59 and <70:
print "Better luck next time."
| exam1 and exam2 are worth 40% together, not individually. Think through the program and see what happens when you get 100 on everything. Do you get a 100 average like you should? Student57 |
Amelia Cipolla
Is that better?
| Better. Colin Potts (But your 'fianlGrade' still isn't 100.) |
| It's not valid Python to say finalGrade>79 and <90 You can say finalGrade>79 and finalGrade<90. You can also say 79. Mark Guzdial |
Hey, what happened to Amelia's (almost) corrected version? .... Disregard my comment above.
The general point, folks is not to edit your code on these pages once we've commented on it and to use only the "add to the page" box. Posting suggested answers or quesions is a good way for all members of the class to see near misses and our comments about them. This is REMOVED challenging than seeing someone else's correct answer.
Amelia Cipolla
Sorry about messing up the system....I was confused. And now I am really confused about my solution. is there still something wrong with it?
Okay, the code I'm looking at right now(!) has expressions in it that look like if x > 79 and < 90 Ellipsis is acceptable in English, but not in Python: If you want to compare x with two values, you have to say if x > 79 and x < 90 (repeating the 'x').
Colin Potts at 7:43p.m., Thursday
| Also, what happened to "You got a D," and check the if statement for "Better luck next time." Student480 |
def finalGrade(exam1,exam2,exam3):
grade=((((exam1 + exam2)/2)*0.40)+(exam3*0.60))
if (grade>=90):
print (grade)
print ("Congratulations, you got an A")
if (grade>=80 and grade<90):
print (grade)
print ("You got a B")
if (grade>=70 and grade<80):
print (grade)
print ("You got a C")
if (grade>=60 and grade<70):
print (grade)
print ("You got a D")
if (grade<60):
print (grade)
print ("Better luck next time")
REMOVED is my attempt. Not elegant, but it appears to work. Student1295
Student933
def finalGrade(exam1, exam2, exam3):
#Exams 1 and 2
totalmidterm = exam1 + exam2
averagemidterm = totalmidterm/2
midterms = .4*averagemidterm
#Exam 3
finalexam = .6*exam3
#final score
finalscore = midterms + finalexam
print finalscore
if finalscore >= 90:
print “Congratulations, you got an A!”
if finalscore >= 80 and finalscore < 90:
print “You got a B.”
if finalscore >= 70 and finalscore < 80:
print “You got a C.”
if finalscore >= 60 and finalscore <70:
print “You got a D.”
if finalscore < 60:
print “Better luck next time.”
hm...i did this: Student1113
def finalGrade(exam1,exam2,exam3):
midtermgrades=((exam1+exam2)*.40)
final=(exam3*0.60)
classgrade=midtermgrades+final
if (classgrade>=90):
print "Congratulations, you got an A!"
if (classgrade<90 and classgrade>=80):
print "You got a B."
if (classgrade<80 and classgrade>=70):
print "You got a C."
if (classgrade<70 and classgrade>=60):
print "You got a D."
if (classgrade<60):
print "Better luck next time."
It looks different from some of the above postings..but it appears to work...any comments?
print "You got a C
Student1113
woah! Ignore my spacing (it's typed right in JES) and I have no idea why there's that "print 'You got a C'" below my last comment...sorry
| Kyla, please read the FAQ on how to post to the coweb. You need to have opening html and pre tags at the beginning of your code and closing pre and html tags at the end of your code. Ashley Coker |
Student1147
def finalGrade(exam1,exam2,exam3):
finalgrade = (((exam1+exam2)/2)*.4)+(exam3*.6)
print finalgrade
if finalgrade >= 90:
print "Congratulations, you got an A!"
if 80 <= finalgrade < 90:
print "You got a B."
if 70 <= finalgrade < 80:
print "You got a C."
if 60 <= finalgrade < 70:
print "You got a D."
if 60 > finalgrade:
print "Better luck next time."
>>> finalGrade(85,96,89)
89.4
You got a B.
>>> finalGrade(100,100,100)
100.0
Congratulations, you got an A!