python计算gpa_在Python中,从s计算GPA

我是Python的新手,我正在上一个教我该语言的课程。现在,我们刚刚学习了条件语句,我的任务是编写基于三个加权类别(如代码所示)计算学生平均绩点的代码。但是,我只能根据一定的百分比打印出GPA。4.0等于94及以上,3.5代表89,3.0代表80,2.5代表75,2.0代表70,1.5代表65,1.0代表60,低于60的任何东西都是0。我的老师说我必须用这些数字。如果百分比不符合这些条件,我不知道如何计算平均绩点。有人能帮忙解决这个问题吗?在#Scores (made up point totals)

avgHwScore = float(input('What was your average homework score? (Out of 5)\n>>> '))

midTerm = float(input('What was your score on the mid-term? (Out of 30)\n>>> '))

finalExam = float(input('What was your score on the final exam? (Out of 50)\n>>> '))

#Converting to decimal

hwDec = avgHwScore/5

midDec = midTerm/30

finalDec = finalExam/50

#Weighted grades

hwWeighted = hwDec*.6

midWeighted = midDec*.2

finalWeighted = finalDec*.2

print('\nThe homework is weighted 60% and the mid-term and final exam are both weighted 20% each\n')

print('You earned ' + str(hwWeighted*100) + '% out of 60% in the homework category')

print('You earned ' + str(midWeighted*100) + '% out of 20% on mid-term category')

print('You earned ' + str(finalWeighted*100) + '% out of 20% on the final exam category\n')

#Final grade

finalGrade = (hwWeighted + midWeighted + finalWeighted)*100

if finalGrade >= 94:

print('Your final grade is ' + str(finalGrade) + '%. You have a 4.0 in the class')

elif finalGrade == 89:

print('Your final grade is ' + str(finalGrade) + '%. You have a 3.5 in the class')

elif finalGrade == 80:

print('Your final grade is ' + str(finalGrade) + '%. You have a 3.0 in the class')

elif finalGrade == 75:

print('Your final grade is ' + str(finalGrade) + '%. You have a 2.5 in the class')

elif finalGrade == 70:

print('Your final grade is ' + str(finalGrade) + '%. You have a 2.0 in the class')

elif finalGrade == 65:

print('Your final grade is ' + str(finalGrade) + '%. You have a 1.5 in the class')

elif finalGrade == 60:

print('Your final grade is ' + str(finalGrade) + '%. You have a 1.0 in the class')

elif finalGrade < 60:

print('Your final grade is ' + str(finalGrade) + '%. You have a 0.0 in the class')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值