#๐Ÿ”’ Need help

69 messages ยท Page 1 of 1 (latest)

stark harnessBOT
#

@scarlet remnant

Python help channel opened

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.

scarlet remnant
#

Further context I can reassure i added the input.txt thats needed into the same directory

ionic timber
#

if you want help with code, paste it -- all of it -- as text, not a screenshot

scarlet remnant
#

I pasted

#

the discord paste

#

of the whole code

ionic timber
#

I see no code

#

I see some screenshots, but those aren't text.

scarlet remnant
#

???

ionic timber
#

ah sorry

scarlet remnant
#

you good!

ionic timber
#

the screenshots are so much more attention-grabbing than the link ๐Ÿ™‚

scarlet remnant
#

hey man shi happens just i beg for support

#

am i not

#

having the file

#

read properly?

ionic timber
#

dunno yet

#

can you paste the data file as text too?

scarlet remnant
#

rn gotchu

ionic timber
#

Oh I think I see it

scarlet remnant
ionic timber
#

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.

scarlet remnant
#

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

ionic timber
#

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

scarlet remnant
#

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

ionic timber
#

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

scarlet remnant
#

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

ionic timber
#

oh well I dunno about that

scarlet remnant
#

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

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

scarlet remnant
#

trying rn

#

โค๏ธ

ionic timber
#

Any remaining discrepancies are "an exercise for the reader"

scarlet remnant
#

The covnvnert has a problem

#

but that actually

#

is sm closer

#

than what I have ๐Ÿ˜ญ

stark harnessBOT
#
Python help channel closed

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