#πŸ”’ how can i fix this

23 messages Β· Page 1 of 1 (latest)

waxen sierraBOT
#

@abstract forge

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.

urban kite
#

what is the problem here currently???

abstract forge
#
def compute_totals_summary(filename):
    new_dict = {}
    
    with open (filename, 'r') as file:
        for line in file:
            line = line.strip()
            parts = line.split()
            
    
        total = 0
        minimum = 100
        average = 0
        
        for num in new_dict.values():
            total += num
        for num in new_dict.values():
            if num < minimum:
                minimum = num
                
        average = total / len(new_dict)
        
        new_average = float(average)
        
    return (f"{new_dict}, {total}, {minimum}, {new_average:.1f}")
pale tiger
#

The exercise asks that you return a tuple but you're returning a string.
A tuple is like a list but with parenthesis.

abstract forge
#

this is where i am at

#

ye but i need to give the average only one decimal

#

my problem now is that my other values are wrong my tuples

urban kite
#

put * before the function call

#

to unpack and let print format it

abstract forge
#

my values are wrong tho

#

why?

#

my max min and average is all wrong

#

i have 4 minutes to deliver

#

i need answer and then explanation pleaseπŸ™

pale tiger
#

You put 'total' where your maximum value should be.
Your minimum calculation is iterating on the unadded dictionary, and therefore is returning the 3 from {Alice:3}
Your average is being divided by 4 instead of 3 because you're counting Alice twice.

warped tree
abstract forge
#

no, i just needed answer than explanation

warped tree
#

That's... spoonfeeding

pale tiger
#

You need to convert the dictionary you built from the file into a dictionary that has the values added up.

waxen sierraBOT
#
Python help channel closed using Discord native close action

This help channel has been closed. 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.