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?
Jim Above Average Sue Below Average Bob Perfect score On Fri, Jul 17, 2009 at 12:48 PM, bob gailer <bgai...@gmail.com> wrote: > Chris Castillo wrote: > >> how would i go about adding the names to a dictionary as a key and the >> scores as a value in this code? >> >> >> # refactored for better use of Python, correct logic, and flow > > scores = {} # empty dictionary > total = 0 > for line in open("bowlingscores.txt", "r"): > if line.strip().isdigit(): > score = int(line) > scores[name] = score > total += score > else: > name = line.strip() > averageScore = total / len(scores) > fileOut = open("bowlingaverages.txt", "w") > fileOut.write("Bowling Report\n" + ("-" * 50) + "\n") > for name, score in scores.items(): > if score == 300: > score = "\tPerfect score!" > elif score < averageScore: > score = "\tBelow average" > elif score > averageScore: > score = "\tAbove average!" > else: > score = "\tAverage!" > print name, score > > > -- > Bob Gailer > Chapel Hill NC > 919-636-4239 >
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor