Skip to content

Update 2-writing-files.md; Handling data in a CSV format#28

Open
goatdjar wants to merge 1 commit intorage:mainfrom
goatdjar:patch-1
Open

Update 2-writing-files.md; Handling data in a CSV format#28
goatdjar wants to merge 1 commit intorage:mainfrom
goatdjar:patch-1

Conversation

@goatdjar
Copy link
Copy Markdown

@goatdjar goatdjar commented Apr 27, 2026

Handling data in a CSV format. https://programming-26.mooc.fi/part-6/2-writing-files#handling-data-in-a-csv-format

The output is wrong. Change from "Emily;41;5" to "Emily;34;3"

Printed values inside save_results function:

Peter
[4, 2, 3, 5, 4, 0, 0]
Paula
[7, 2, 8, 3, 5, 4, 5]
Susan
[3, 4, 3, 5, 3, 4, 4]
Emily
[6, 6, 5, 5, 0, 4, 8] -> 34

Tested with the following:

def grade(points):
    if points < 20:
        return 0
    elif points < 25:
        return 1
    elif points < 30:
        return 2
    elif points < 35:
        return 3
    elif points < 40:
        return 4
    else:
        return 5
def grade(points):
    return sum(points >= t for t in [20, 25, 30, 35, 40])
def grade(points):
    return bisect.bisect([20, 25, 30, 35, 40], points)
def grade(points):
    return min(5, max(0, (points - 15) // 5))

The Output:

─────┼────────────────────────────
     │ File: results.csv
─────┼────────────────────────────
   1 │ Peter;18;0
   2 │ Paula;34;3
   3 │ Susan;26;2
   4 │ Emily;34;3

Change wrong output. From Emily;41;5 -> Emily;34;3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant