#๐ Need help
69 messages ยท Page 1 of 1 (latest)
@scarlet remnant
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Further context I can reassure i added the input.txt thats needed into the same directory
if you want help with code, paste it -- all of it -- as text, not a screenshot
???
ah sorry
the screenshots are so much more attention-grabbing than the link ๐
hey man shi happens just i beg for support
am i not
having the file
read properly?
rn gotchu
Oh I think I see it
you're calling "split" to break the line into fields.
and you're assuming the second field is a float.
But in fact, it's the person's last name.
So if im correct youre stating the i have it as split into break the lines but it's geniuely one of the last names?
Just clarifying right quick
ya
try this ```py
def calculate_score(scores, dd):
scores.remove(min(scores))
scores.remove(max(scores))
return round(sum(scores) / len(scores) * dd, 1)
def main() -> None:
with open("input.txt") as file:
print("Name DD Score")
for line in file:
given_name, surname, dd, *scores = line.strip().split()
print(f"{given_name=} {surname=} {dd=} {scores=}")
try:
dd = float(dd)
scores = list(map(float, scores))
except ValueError:
print("Error: Invalid data format in the input file.")
final_score = calculate_score(scores, dd)
print(given_name, surname, dd, final_score)
if name == "main":
main()
wfm
When I do that
It only outputs
bob smith
name
and not the rest
how would I include the others then?
i also did for the split area
I see this ```
main()
Name DD Score
given_name='Bob' surname='Smith' dd='1' scores=['7.5', '0.5', '8.5', '6.5', '2.5', '8.0', '9.5']
Bob Smith 1.0 6.6
given_name='Bob' surname='Smith' dd='5' scores=['0.5', '5.5', '5.5', '0.5', '9.5', '10.0', '6.5']
Bob Smith 5.0 27.5
given_name='Paul' surname='Phillips' dd='3' scores=['2.5', '2.0', '8.0', '9.0', '4.5', '7.0', '5.5']
Paul Phillips 3.0 16.5
given_name='Paul' surname='Phillips' dd='1' scores=['6.0', '1.5', '2.5', '4.0', '1.0', '10.0', '8.5']
Paul Phillips 1.0 4.5
given_name='Molly' surname='Brown' dd='1' scores=['9.0', '5.0', '1.5', '9.0', '4.0', '0.0', '8.0']
Molly Brown 1.0 5.5
given_name='Molly' surname='Brown' dd='2' scores=['4.5', '4.5', '0.5', '3.0', '1.5', '0.5', '1.0']
Molly Brown 2.0 4.2
dunno why you're seeing something different
Im a slow poke
had the other part added
that works
but I need the output
identical as this
for the autograder
to match it
oh well I dunno about that
I put "\t"
for it to work
but it only adds bob smith name
try to run this
and see what I mean @ionic timber
try this ```py
def calculate_score(scores, dd):
scores.remove(min(scores))
scores.remove(max(scores))
return round(sum(scores) / len(scores) * dd, 1)
def main() -> None:
with open("input.txt") as file:
print("Name DD Score")
for line in file:
name, dd, *scores = line.strip().split("\t")
try:
dd = float(dd)
scores = list(map(float, scores))
except ValueError as e:
print(f"{e} in {line=}.")
continue
final_score = calculate_score(scores, dd)
print(name, dd, final_score, sep="\t")
if name == "main":
main()
I get ```
uv run python nikto.py
Name DD Score
Bob Smith 1.0 6.6
Bob Smith 5.0 27.5
Paul Phillips 3.0 16.5
Paul Phillips 1.0 4.5
Molly Brown 1.0 5.5
Molly Brown 2.0 4.2
seems pretty close, anyway
Any remaining discrepancies are "an exercise for the reader"
The covnvnert has a problem
but that actually
is sm closer
than what I have ๐ญ
LMAO
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
๐ Need help