以下是用于打印和计算加权考试成绩的代码:
def exam(weight,score_earned,score_shift):
if (score_shift==1):
shift_amount=input("What was the shift amount?")
score_earned=int(shift_amount+score_earned)
if (score_earned >100):
score_earned=100
print("Total points = "+str(score_earned)+str("/100"))
weighted_score=int((score_earned/100.0)*weight)
print("Your weighted score = "+str(weighted_score)+"/"+str(weight))
return weighted_score
def exam_1():
print("Midterm 1:")
exam(input("Weight 0-100?"),input("Score earned?"),input("Were scores shifted (1= yes 2=no)? "))
然后我添加了另一个具有不同名称的类似函数,所以...
def exam_2():
print("\nMidterm 2:")
exam(input("Weight 0-100? "),input("Score earned? "),input("Were scores shifted (1= yes 2=no)? "))
之后,我将这两个加在一起,这就是我的问题所在。
overall_percentage =int(exam_1() +exam_2())
我希望代码使用返回的weighted_score为每个分数添加加权分数。虽然,当我运行代码时,它给了我这个错误:
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
我该如何解决?
这也是示例输出-一切都正常,除了total_percentage之外,这使我认为return语句出了点问题:
Midterm 1:
Weight 0-100? 50
Score earned? 88
Were scores shifted (1= yes 2=no)? 2
Total points = 88/100
Your weighted score = 44/50
Midterm 2:
Weight 0-100? 50
Score earned? 88
Were scores shifted (1= yes 2=no)? 2
Total points = 88/100
Your weighted score = 44/50
答案 0 :(得分:3)
您的函数rabbitmqctl set_disk_free_limit mem_relative <fraction>
和img.button:hover ~ p.text {
color: rgb(88, 202, 230);
}
p {
font-weight: 300;
transition: color 1s ease;
}
不返回任何值(= <img class='button' src='//placehold.it/100?text=avatar' />
<p class='text'>Profile</p>
)。
这就是exam_1
产生exam_2
并引发您所看到的异常的原因:
TypeError:+不支持的操作数类型:“ NoneType”和“ NoneType”
您可以轻松解决该问题:
None
和
exam_1() + exam_2()