If you have any questions, comments or issues with this project please post them here!
Hello, I’m having an error when trying to load the high.scores file from Day 49 on 100 days of code(for Python). Everything appears to be ok and I’m not sure what I’m doing wrong. I can link my replit to the forum for help.
You must make a file named
high.score. Also, welcome to community @sonicx180 !
you beat me again. Next time, mention me at the top of your post
Hi! Thank you for welcoming me to the community and for the quick reply. I’m still not clear about what I’m doing wrong.
I thought I loaded the file, but I’m still getting an error message about it loading.
yes, you just need to make a file, try press the file icon that has a plus in it, and then make a file named
high.score and put a bunch of numbers (scores) in it
John Smith 100 John Doe 200
EDIT: reveal this by closing the tutorial and pressing the reveal sidebar
OK. I’ll try again. I understand that in theory but it hasn’t been working with the code. This is the first time I’ve gotten stuck.
Hey there, the code provided is wrong, you are correct! Try this:
import os, time f = open("high.score", "r") scores = f.read().split("\n") f.close() highscore = 0 name = None for rows in scores: data = rows.split() if data != : if int(data[-1]) > highscore: highscore = int(data[-1]) name = " ".join(data[:-1]) print("The winner is", name, "with", highscore)
Here: you can fork
I managed to fix it!
Thank you for the feedback and the new code, it was very helpful. I’m completely self-taught and I’m sure my process would be faster if I asked for more help along the way. Getting help was easier than I expected it to be. Thanks again!!
you’re welcome, hope you enjoy the community
Hi, not sure if this is a bug or I’m doing something wrong. I’ve opened the high.score file that was provided, you can see it open on the bottom tab but whenever I try to run the code, it says no such file or directory.
the thing has the wrong code sadly, to fix this either:
- or just put this in
f = open(".tutorial/high.score", "r")
- create a NEW file called high.score and put:
DMO 20332 K8T 398398398938 BRI 323232 SAM 494949
I am struggling with this project. and cannot remember how the index and Len() function work. Could someone please give me a refresher on this in a way I can remember it.
Here’s an example:
myList = ["x", "y", "z"]
We created a list with 3 items.
len function takes an iterable and returns the number of elements in it. You can remember it as “len” is short for “length” and the function returns the length of the iterable.
print(len(myList)) # This outputs 3 because there are 3 elements in the list
index returns the index of an element in the list.
print(myList.index("x")) # This outputs 0 because list indices start at 0 and "x" is the first item we defined in the list
I know what
.split() does but what does
\n represents a newline character, so it does the same as
.split() except it splits by newline characters.
can you please explain 3-5 lines?
i cant understand how he compare the numbers with that method i mean when he wrote (highscore=0) and (if data>highscore:)like data is always biger than 0 but it worked so well i cant got it please explain?>.