在我的数据文件中
60,66,88,90,44,90,80,77
所有数字都在一行中
这是我的代码,它没有给我平均数字
inFile3 = open("data2.txt","r")
global gradeVar
gradeVar = len(gradeArray)
global Total
Total = 0
for Numbers in inFile3:
Total = Total + int(Numbers)
inFile3.close()
global averageVar
averageVar = Total/gradeVar
return averageVar
Run Code Online (Sandbox Code Playgroud)
这是错误
Traceback (most recent call last):
File "program.py", line 81, in <module>
main()
File "program.py", line 5, in main
averageVar = Average()
File "program.py", line 39, in Average
Total = Total + int(Numbers)
ValueError: invalid literal for int() with base 10: '60,66,88,90,44,90,80,77\n'
Run Code Online (Sandbox Code Playgroud) 这是我的代码
def main():
# This code reads in data.txt and loads it into an array
# Array will be used to add friends, remove and list
# when we quit, we'll overwrite original friends.txt with
# contents
print"Welcome to the program"
print "Enter the correct number"
print "Hockey fan 1, basketball fan 2, cricket fan 3"
choice = input("Select an option")
while choice!=3:
if choice==1:
addString = raw_input("Who is your favorite player??")
print "I love Kessel"
elif choice==2:
remInt = …Run Code Online (Sandbox Code Playgroud) def main():
# This code reads in data.txt and loads it into an array
# Array will be used to add friends, remove and list
# when we quit, we'll overwrite original friends.txt with
# contents
print"Welcome to the program"
print "Enter the correct number"
print "Hockey fan 1, basketball fan 2, cricket fan 3,Numbers of favorite players-4"
choice = input("Select an option")
while choice!=3:
if choice==1:
addString = raw_input("Who is your favorite player??")
print "I love Kessel"
elif choice==2: …Run Code Online (Sandbox Code Playgroud)