python学生成绩评价_用于计算学生成绩的Python程序

# NOTE: I haven't checked whether your math is right, or

# if the computed values are correct. I did however get your

# script to work.

def read_test_scores():

print("ENTER STUDENT ID:")

id = int(input())

print("ENTER EXAM SCORE:")

exam = int(input())

print("ENTER ALL TEST SCORES:")

score1 = int(input())

score2 = int(input())

score3 = int(input())

score4 = int(input())

score5 = int(input())

score6 = int(input())

score7 = int(input())

sum = (score1 + score2 + score3 + score4 + score5 + score6 + score7)

tavge = sum / 7.0

# NOTE: if you want to use any variables from this function,

# then you have to"bring them outside" by"returning"

# them. Here, I return the values tavge, id, and exam. I noticed

# that bringing out"exam" is necessary since you'll

# be using it later on.

return tavge, id, exam

def compute_final_score(tavge, exam):

final_score = 0.4 * tavge + 0.6 * exam

return final_score

def get_letter_grade(final_score):

if 90 <= final_score <= 100:

grade = 'A'

elif 80 <= final_score <= 89:

grade = 'B'

elif 70 <= final_score <= 79:

grade = 'C'

elif 60 <= final_score <= 69:

grade = 'D'

else:

grade = 'F'

return grade

def print_comment(grade):

# NOTE `=` is for assignment. We use it when we want to

# tell python to make a variable mean something. For example:

# a ="some_name" basically means that when we call a, it would

# return the string"some_name".

# What you want to use here is `==` which is the equality operator.

# This checks whether or thing are equal.

if grade == 'A':

print"COMMENT: Very Good"

elif grade == 'B':

print"COMMENT: Good"

elif grade == 'C':

print"COMMENT: Satisfactory"

elif grade == 'D':

print"COMMENT: Need Improvement"

elif grade == 'F':

print"COMMENT: Poor"

# NOTE 1: you need to assign the function results to a

# variable (or variables), otherwise, the result or return value

# will go nowhere and you can't use it

tavge, id, exam = read_test_scores()

print"TEST AVERAGE IS: " + str(tavge)

# NOTE 2: variable names do not have to be the same as

# the name in their respective functions. Here, you can see

# that it will still run even if I changed the variable

# name final_score to my_variable. Although, of course, using

# final_score would still work.

# NOTE 3: the final_score function requires 2 inputs,

# namely tavge and exam. This basically means that you have to feed

# it with these 2 values for it to work. I took the

# tavge and exam variables as the results from your read_test_scores

# function

my_variable = compute_final_score(tavge, exam)

print"FINAL SCORE IS: " + str(my_variable)

grade = get_letter_grade(my_variable)

print"LETTER GRADE IS: " + str(grade)

print_comment(grade)

# FINAL NOTE: I haven't commented regarding coding style etc (like say

# for instance, there are best practices regarding variable names

# within functions, that is, if they should be similar to variable names

# outside the function), but regardless, the code is a good start. I

# would also advise you to try to narrow down your question first

# before posting. This can be done by running your code, and searching

# the internet for the particular erro messages, and if you're still stuck,

# ask here on stackoverflow.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值