I am writing a program to find the mean, median and mode of a list. Rather than doing all of this manually, I am using Python's "Statistics" module, which has built in functions for each of these.
However I found a problem, when there is no mode (that is, when there is more than one answer for the mode (e.g., when the list = [1,3,5,7,10])) the module throws an error:
statistics.StatisticsError: no unique mode; found 5 equally common values
Im not sure how I would specifically use an except statement to be executed when there is an error like this, I think I can do something like
try:
print("The Mode = ",statistics.mode(userNumbers))
except statistics.StatisticsError
print("There was an error with the statistics module")
To show that there was a problem with the statistics module, however when I try
try:
print("The Mode = ",statistics.mode(userNumbers),")
except statistics.StatisticsError: no unique mode; found 5 equally common value:
print("There is no single mode")
Python thinks that I am trying to end the line at the colon after Error, I tried using a backslash ("\") to skip the colon but that didnt work, and im not sure how else I would specifiy the error that was given off without ignoring that character.
Is there a way to ignore that colon or would I have to do something else altogether?
Thanks to anyone that atleast looks at my problem <3