#π how can i fix this
23 messages Β· Page 1 of 1 (latest)
@abstract forge
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.
what is the problem here currently???
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}")
The exercise asks that you return a tuple but you're returning a string.
A tuple is like a list but with parenthesis.
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
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π
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.
how do i fix it
Your lack of planning isn't our emergency and we aren't going to spoonfeed you the solution.
no, i just needed answer than explanation
That's... spoonfeeding
You need to convert the dictionary you built from the file into a dictionary that has the values added up.
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.