Question
i'm getting this error in my python program number = int (number) ValueError: invalid literal for int() with base 10: 'Sum:' def main(): # open
i'm getting this error in my python program
number = int (number)
ValueError: invalid literal for int() with base 10: 'Sum:'
def main():
# open the InputNumber.txt file for reading
urFile = open('numbers.txt','r')
# vairable declaration and settinginitial for vairables
sum,max,min,num,average =0,None,None,0,None
# running loop through each numberin InputNumber.txt file
for number in urFile.read().split():
# convert to a numberinto integer instead of string
number = int(number)
# calculate sum of allnumbers
sum += number
# if max and min areNone
if max is None:
max =number
if min is None:
min =number
# find minimumnumber
if number < min:
min =number
# find maximumnumber
if number > max:
max =number
# increment counter by1
num += 1
# calculate the average
totalAverage = float(sum/num)
# display result
print('sum is', sum)
print('max is', max)
print('min is', min)
print('total of values is ', num)
print('average total is'.format(average))
# open numbers.txt in append createmode
outFile = open('numbers.txt')
# write the above datato the file
outFile.write('um is'+str(sum)+'')
outFile.write('max is'+str(max)+'')
outFile.write('min is'+str(min)+'')
outFile.write('total of valuesis'+str(num)+'')
outFile.write('average totalis'.format(average))
# call the main function
main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started