Code that I currently have, is as it appears not to be using the variable i initizied inside a if statement. I got the idea to do the code this way from a much older wiser programer. I am unsure why I am getting this error, is in some way my syntax off or is there something I am missing?
Below is segment of the code in question and the out put below that. As well after that, is the entire code for context. For the entire code, the code in question is down at the bottom in the processScores method. Thank you
def processScores( file, Score):
#opens file using with method, reads each line with a for loop. If content in line
#agrees with parameters in if statements, executes code in if statment. Otherwise, ignores line
with open(file,'r') as f:
for line in f: #starts for loop for all if statements
if line[0].isdigit:
start = int(line[0])
Score.initialScore(start) #checks if first line is a number if it is adds it to intial score
and now the output explaining the error
processScores('theText.txt',Score)
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
processScores('theText.txt',Score)
File "C:/Users/christopher/Desktop/hw2.py", line 49, in processScores
Score.initialScore(start) #checks if first line is a number if it is adds it to intial score
TypeError: initialScore() missing 1 required positional argument: 'start'
and now the total code, for context. Remember the code in question is more towards the bottom
class Score:
# class to hold a running score, from object to parameter
# also to set number of scores that contribute to total of 1
def __init__(self):
#initalizes the running score and score input accumilators
self.runScore = 0
self.scoreInputs = 0
self.runScore = 0
def initialScore(self, start):
#takes the initial score in line one of the file and updates
#the running score to the inital score
self.runScore += start
print('Grabing intial score from file, inital score set to ' + start)
def updateOne (self, amount):
#updates running score by amount and Score input by 1
self.runScore += amount
self.scoreInputs += 1
print('Adding ' + amount + ' to score, number of scores increased by 1. Current number of points scored ' + self.runScore + ', current number of scores at ' + self.scoreInputs)
def updateMany(self,lst):
#updates running score by the sum of the list and score inputs by the amount of
# number of items in the list
self.runScore += sum(lst)
self.scoreInputs += len(lst)
print('Adding the sum of ' + len(lst) + 'scores to score. Score increased by ' + sum(lst) + '. current number of points scored ' + self.runScore + ', current number of scores at ' + self.scoreInputs)
def get(self):
#returns the current score based on total amount scored
print('Grabbing current score')
print(self.runScore)
def average(self):
#returns the average of the scores that have contributed to the total socre
print('calculating average score')
print(self.runScore // self.scoreInputs)
def processScores( file, Score):
#opens file using with method, reads each line with a for loop. If content in line
#agrees with parameters in if statements, executes code in if statment. Otherwise, ignores line
with open(file,'r') as f:
for line in f: #starts for loop for all if statements
if line[0].isdigit:
start = int(line[0])
Score.initialScore(start) #checks if first line is a number if it is adds it to intial score
if line == 'o' or line == 'O':
amount = int(next(f))
Score.updateOne(amount) #if line contains single score marker, Takes content in next line and
#inserts it into updateOne
if line == 'm'or line == 'M':
scoreList = next(f)
lst = []
for item in scoreList:
lst.append(item)
Score.updateMany(lst) # if line contains list score marker, creates scoreList variable and places the next line into that variable
# creates lst variable and sets it to an empty list
# goes through the next line with the for loop and appends each item in the next line to the empty list
# then inserts newly populated lst into updateMany
if line == 'X':
Score.get(self)
Score.average(self) # if line contains terminator marker. prints total score and the average of the scores.
# because the file was opened with the 'with' method. the file closes after