## Midterm Exam 1 Review Spring 2004: Compute the grade

```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
 Maybe the "=>" rather than ">="? Mark Guzdial

Amelia Cipolla
```def finalGrade(exam1, exam2, exam3):
value1=(0.4*((exam1+exam2)/2))
value2=(0.6*exam3)
print "Congradulations, you got an A!"
print "You got a B."
print "you got a C."
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?

 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):
print ("Congratulations, you got an A")
print ("You got a B")
print ("You got a C")
print ("You got a D")
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):
final=(exam3*0.60)
print "Congratulations, you got an A!"
print "You got a B."
print "You got a C."
print "You got a D."
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):
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."
print "Better luck next time."```

89.4
You got a B.
100.0
Congratulations, you got an A!

```def ComputeGrade(Score1, Score2, Score3):
FinalGrade = ((Score1 + Score2) x 0.4) + (Score3 x 0.6)
print "Congratulations, you got an A!"
print "You got a B."
print "You got a C."
print "You got a D."
else:
print "Better luck next time."
```

Student971

 Rachel, you're missing the comparison operators in the second part of each 'if' statement. Also, when multiplying use the asterisk not 'x'. Anybody reading this, who is confused by elif, pretend elif is if. Colin Potts