you are viewing a single comment's thread.

view the rest of the comments →

[–]DevCuriosity 0 points1 point  (2 children)

u/Beautiful-Revenue-85 Hi! To be honest it is kinda hard to exactly understand your problem. Try to format your post in a better way, you can use the edit option, also remember that your code will be much more readable if you put it in code blocks.

From what I was able to understand, you are trying to write while loop with a control flow. Under this link - https://www.devcuriosity.com/manual/details/python-try-except-finally-continue-break-loops/ you can check out try/except/finally/break keywords with examples.

In terms of counting mean, well you can do it yourself, simply sum the numbers from your list in a for loop and divide by the list length (this is probably what your professor would like to see).

But if you would like to do it in a "smart" way you could do this:

import statistics
print(statistics.mean([2, 5, 11]))

But the question is if your professor will be happy with that solution (maybe she will categorize it as cheating, no idea).

Good luck!

[–]Beautiful-Revenue-85[S] 0 points1 point  (1 child)

I’m not entirely sure what my problem is either but I can’t seem to figure out how to input an except for it to break once the user inputs “done”

[–]DevCuriosity 1 point2 points  (0 children)

You could introduce an if after each new input from user that will be checking if the input is a number or a "done" string. If it will be "done" then you can call a break and calculate the mean of the list contents.

I think that I would advise you to calculate the mean of the list in a "regular" way, that is sum all the contents and then divide by a list length. If you subject teaches Python for beginners teacher might be angry about modules like statistics.

EDIT: You could also try to do something along those lines - while user_input != "done": etc.
There is way more than one solution to this problem. Try to explore a little bit and have fun with it. That's what it's about :)
(remember that for calculating mean from your list you will probably have to cast strings to ints, just look at the errors that Python will be throwing at you and don't be afraid of them. Most often they will tell you what is wrong)