【发布时间】:2019-07-12 02:14:20
【问题描述】:
我需要有关 Python 编码问题的帮助。
我必须计算学生的 GPA。程序必须询问他们上多少门课,然后要求他们输入每门课的成绩以及是否加权。
然后程序应该输出包括小数位在内的平均 GPA,我的主程序必须调用该函数。
该问题给出了与给定字母等级相关的非加权和加权数字分数的图表: gpa chart
这是我目前所拥有的:
def average (c):
div = c
avg =(1.0*(sum(scores))/div)
#****************MAIN********************
c = input("How many classes are you taking?")
print ("You are taking " + str(c) + " classes.")
x = input("Enter your letter grade.")
w = int(input("Is it weighted? (1 = yes)")
while (c <= 7): #Here it is saying that there is a syntax error because I input a while loop. I don't know why it is saying this.
if (x == A):
if (w == 1):
print ("Your GPA score is 5")
else:
print ("Your GPA score is 4")
elif (x == B):
if (w == 1):
print ("Your GPA score is 4")
else:
print ("Your GPA score is 3")
elif (x == C):
if (w == 1):
print ("Your GPA score is 3")
else:
print ("Your GPA score is 2")
elif (x == D):
if (w == 1):
print ("Your GPA score is 2")
else:
print ("Your GPA score is 1")
elif (x == F):
if ( w == 1):
print ("Your GPA score is 1")
else:
print ("Your GPA score is 0")
scores = []
list.append(x)
average(c)
任何帮助将不胜感激! :)
【问题讨论】:
-
您具体要寻求什么帮助?
-
我们这里没有水晶球。我们需要更多关于正在发生的事情的信息:(
-
我在问我的代码是否可行。我正在通过 Edhesive 参加计算机科学入门课程,它的代码终端一直说存在“错误语法”,要求用户在主程序启动后立即输入 c 的值。我不知道该怎么办。任何帮助都会很棒!
-
这不是你在 python 中调用函数的方式。
return语句在定义时进入函数内部,然后在您的主块中使用func()或在您的情况下使用classes(c)或gpacalc(x,w)调用函数 -
非常感谢@G.Anderson!这很有帮助。
标签: python function return average gpa