【发布时间】:2021-06-28 02:56:41
【问题描述】:
try:
print("This program will allow you to calculate the average of your califications \nonly accepts 4 grades")
opc=int(input("type (1) to calculate a simple average or type (2) \nto calculate the weighted average: "))
n1 =int(input("Write your first calification: "))
n2 = int(input("Write your second calification: "))
n3= int(input("Write your third calification: "))
n4= int(input("Write your fourth calification: "))
def promedio(opc,prom):
if opc == 1:# simple average calification
p= (n1+n2+n3+n4)/4
print("your average calification is : ",p)
elif opc == 2:# weight average calification
p1=int(input("insert the weighted of your first calification: "))
p2=int(input("insert the weighted of your second calification: "))
p3=int(input("insert the weighted of your third calification: "))
p4=int(input("insert the weighted of your fourth calification: "))
p=p1*n1+p2*n2+p3*n3+p4*n4
print("your weighted average calification is: ",p)
else:
print("your average calification is")
return prom
x = promedio(p)
print(x)
except:
print("write only a number 1 or 2")
【问题讨论】:
-
我希望你知道
x = promedio(p)你传递了一个参数,但函数需要 2 个 -
你没有给这个变量 p 赋值。你在参数中传递它
-
p在函数内部定义。这将导致错误