so could I also replace the score of each bowler (key value) in the dictionary with a new key such as "below average" or "above average" according to each if-elif-else structure and then write to a text file in the following format?<br>
<br>Jim Above Average<br>Sue Below Average<br>Bob Perfect score<br><br><div class="gmail_quote">On Fri, Jul 17, 2009 at 12:48 PM, bob gailer <span dir="ltr"><<a href="mailto:bgailer@gmail.com">bgailer@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">Chris Castillo wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
how would i go about adding the names to a dictionary as a key and the scores as a value in this code?<br>
<br>
<br>
</blockquote></div>
# refactored for better use of Python, correct logic, and flow<br>
<br>
scores = {} # empty dictionary<br>
total = 0<br>
for line in open("bowlingscores.txt", "r"):<br>
if line.strip().isdigit():<br>
score = int(line)<br>
scores[name] = score<br>
total += score<br>
else:<br>
name = line.strip()<br>
averageScore = total / len(scores)<div class="im"><br>
fileOut = open("bowlingaverages.txt", "w")<br>
fileOut.write("Bowling Report\n" + ("-" * 50) + "\n")<br></div>
for name, score in scores.items():<div class="im"><br>
if score == 300:<br>
score = "\tPerfect score!"<br></div>
elif score < averageScore:<br>
score = "\tBelow average"<br>
elif score > averageScore:<br>
score = "\tAbove average!"<br>
else:<br>
score = "\tAverage!"<br>
print name, score<div><div></div><div class="h5"><br>
<br>
-- <br>
Bob Gailer<br>
Chapel Hill NC<br>
919-636-4239<br>
</div></div></blockquote></div><br>