Python Print语句默认为first';如果';语句,无论给定的输入是什么

Python Print语句默认为first';如果';语句,无论给定的输入是什么,python,python-3.x,Python,Python 3.x,我对python非常陌生,所以这段代码可能是一团乱麻,但我遇到的问题是,无论计算的平均值是多少,代码都在执行第一个“if”语句(即,计算的平均值是76.0,但它仍然在执行“a”级,而不是“C”级)。我做错了什么 此外,为了提供信息,代码应该让用户输入四个测试分数,并且代码必须在70-85的范围内随机分配第五个测试的分数,计算并返回所有五个测试分数的平均值,并根据平均值分配分数 def rand(): import random num5 = random.randint(70,8

我对python非常陌生,所以这段代码可能是一团乱麻,但我遇到的问题是,无论计算的平均值是多少,代码都在执行第一个“if”语句(即,计算的平均值是76.0,但它仍然在执行“a”级,而不是“C”级)。我做错了什么

此外,为了提供信息,代码应该让用户输入四个测试分数,并且代码必须在70-85的范围内随机分配第五个测试的分数,计算并返回所有五个测试分数的平均值,并根据平均值分配分数

def rand():
    import random
    num5 = random.randint(70,85)
    calcAverage(num5)

def calcAverage(num5):
    num1 = float(input("Enter the first test score: "))
    num2 = float(input("Enter the second test score: "))
    num3 = float(input("Enter the third test score: "))
    num4 = float(input("Enter the fourth test score: "))
    print("\nThe random test score generater on your behalf was", num5)
    total = num1 + num2 + num3 +num4 + num5
    average = total // 5
    letterGrade(average)

def letterGrade(average):
    if average >= 90.00 and average <= 100.00:
        print("The average of five test scores is {:.1f}.".format(average),"and the letter grade awarded is A.")

    elif average >= 80.00 and average <= 89.99:
        print("The average of five test scores is {:.1f}.".format(average),"and the letter grade awarded is B.")

    elif average >= 70.00 and average <= 79.99:
        print("The average of five test scores is {:.1f}.".format(average),"and the letter grade awarded is C.")

    elif average >= 60.0 and average <= 69.99:
        print("The average of five test scores is {:.1f}.".format(average),"and the letter grade awarded is D.")

    else:
        print("The average of five test scores is {:.1f}.".format(average),"and the letter grade awarded is F.")

rand()
def rand():
随机输入
num5=random.randint(70,85)
平均值(num5)
def平均值(num5):
num1=浮动(输入(“输入第一个测试分数:”)
num2=浮动(输入(“输入第二个测试分数:”)
num3=浮动(输入(“输入第三个测试分数:”)
num4=浮动(输入(“输入第四个测试分数:”)
打印(“\n代表您的随机测试分数生成器为”,num5)
总计=num1+num2+num3+num4+num5
平均数=总数//5
等级(平均)
def等级(平均值):

如果average>=90.00,average=80.00,average=70.00,average=60.0,average,我看一下就可以了。你能再检查一下缩进吗?每个if的内容都应该相对于if条件本身使用单个选项卡缩进。当我刚刚复制、粘贴并运行它时,它对我来说效果很好,但看起来编辑它的人清理了缩进--现在试试,看看它现在是否对你也起作用。修复缩进解决了问题,非常感谢你们!在我看来,快速看一眼就可以了。你能再检查一下缩进吗?每个if的内容都应该相对于if条件本身使用单个选项卡缩进。当我刚刚复制、粘贴并运行它时,它对我来说效果很好,但看起来编辑它的人清理了缩进--现在试试,看看它现在是否对你也起作用。修复缩进解决了问题,非常感谢你们!