程序代写代做代考 Programming Exercise 6-3
Programming Exercise 6-3
Programming Exercise 5-15
# main function
def main():
# Local variables
average = 0.0
score1 = 0.0
score2 = 0.0
score3 = 0.0
score4 = 0.0
score5 = 0.0
# Get scores
score1 = float(input(‘Enter score 1: ‘))
score2 = float(input(‘Enter score 2: ‘))
score3 = float(input(‘Enter score 3: ‘))
score4 = float(input(‘Enter score 4: ‘))
score5 = float(input(‘Enter score 5: ‘))
# Calculate average grade
average = calc_average(score1, score2, score3, score4, score5)
#Display grade and average information in tabular form
print(‘score numeric grade letter grade’)
print(‘—————————————————-‘)
print(‘score 1: ’, score1, ‘ ’, determine_grade(score1))
print(‘score 2: ’, score2, ‘ ’, determine_grade(score2))
print(‘score 3: ’, score3, ‘ ’, determine_grade(score3))
print(‘score 4: ’, score4, ‘ ’, determine_grade(score4))
print(‘score 5: ’, score5, ‘ ’, determine_grade(score5))
print(‘—————————————————-‘)
print (‘Average score: ’, average, ‘ ’,
determine_grade(average))
# The calc_average function returns average of 5 grades
def calc_average(s1, s2, s3, s4, s5):
return (s1 + s2 + s3 + s4 + s5) / 5.0
# The determine_grade function receives a numeric
# grade and returns the corresponding letter grade
def determine_grade(score):
if score >= 90:
return ‘A’
elif score >= 80:
return ‘B’
elif score >= 70:
return ‘C’
elif score >= 60:
return ‘D’
else:
return ‘F’
# Call the main function.
main()