我该如何解决这个问题?我知道错误在第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))
答案 0 :(得分: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))
在python默认情况下输入被视为字符串,当你添加两个字符串56
和4
时,它只会给你另一个字符串564
,它连接但你不能分割字符串因此你就错了。