2017-06-04 106 views
-5

我该如何解决这个问题?我知道错误在第8行(g = f/5),但我该如何解决这个错误?如何解决这个问题?

a = input("Enter a number: ") 
b = input("Enter a second number: ") 
c = input("Enter a third number: ") 
d = input("Enter a fourth number: ") 
e = input("Enter a fifth number: ") 

f = a+b+c+d+e 
g = f/5 

print ("The average of these numbers is "+str(g)) 
+3

看看[问] – pvg

+0

给出的错误是什么?此外,StackOverflow是关于要求特定的问题,而不是张贴代码,并要求人们如何解决这个问题 – CryptoCat

+0

如果错误是'g',那么我最好的猜测将是除法给出一个整数,你可以改变为:'g = float( F)/ 5'。但是,我们只能用很少的信息来猜测 – Nuageux

回答

2
a = int(input("Enter a number: ")) #if you want user to allow non-integer number tan use float instead of int 
b = int(input("Enter a second number: ")) 
c = int(input("Enter a third number: ")) 
d = int(input("Enter a fourth number: ")) 
e = int(input("Enter a fifth number: ")) 

f = a+b+c+d+e 
g = f/5 

print ("The average of these numbers is "+str(g)) 

在默认输入蟒蛇被当作字符串,当你添加两个字符串564它只是给你另一个字符串564这是串联但因此你有错误你不能分割字符串那条线。