用python计算绩点的代码_计算学生的平均绩点GPA的python代码

print(‘welcome to the GPA calculator.’)

print(‘please enter all your letter grades,one per line.’)

print(‘enter a blank line to designate the end.’)

#map from letter grade to point value

points={‘A+’:4.0,‘A’:4.0,‘A-’:3.67,‘B+’:3.33,‘B’:3.0,‘B-’:2.67,‘C+’:2.33,‘C’:2.0,‘C’:1.67,‘D+’:1.33,‘D’:1.0,‘D-’:1.0,‘F’:0.0}

num_course=0

total_points=0

done=False

while not done:

grade = input() #read line from user

if grade==’’: #empty line was entered

done=True

elif grade not in point: #unrecognized grade entered

print("Unknow grade ‘{0}’ being ignored ".format(grade))

else:

num_course+=1

total_point+=points[grade]

if num_course>0: #avoid diversion by zero

print(‘your GPA is {0;.3}’.format(total_points/num_course))

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值