""" File: exam_score.py Purpose: Compute the exam score needed by a student to get a desired grade Run: python exam_score.py Input: Student's scores on all work except the final exam Student's desired final average Output: Exam score needed to get desired final average Note: This version uses a function to compute the weighted score on all the assignments prior to the final exam. """ #---------------------------------------------------------------------- def prior_to_exam(hwk, hwk_pct, p1, p2, p12_pct, p3, p4, p5, p345_pct, mt1, mt2, mt_pct): """Find the weighted score of a student's grades prior to the final exam. """ to_date_avg = hwk_pct*hwk + p12_pct*(p1+p2) + p345_pct*(p3+p4+p5) + \ mt_pct*(mt1+mt2) return to_date_avg hwk_pct = 0.15 p12_pct = 0.06 p345_pct = 0.08 mt_pct = 0.12 exam_pct = 0.25 hwk_str = raw_input("Enter your homework average\n") hwk = float(hwk_str) p1 = float(raw_input("Enter your p1 score\n")) p2 = float(raw_input("Enter your p2 score\n")) p3 = float(raw_input("Enter your p3 score\n")) p4 = float(raw_input("Enter your p4 score\n")) p5 = float(raw_input("Enter your p5 score\n")) mt1 = float(raw_input("Enter your mt1 score\n")) mt2 = float(raw_input("Enter your mt2 score\n")) print avg = float(raw_input("Enter your desired final average\n")) to_date_avg = prior_to_exam(hwk, hwk_pct, p1, p2, p12_pct, p3, p4, p5, p345_pct, mt1, mt2, mt_pct) exam = (avg - to_date_avg)/exam_pct print "Final exam score should be", exam