Answered step by step
Verified Expert Solution
Question
1 Approved Answer
def calculate _ mean ( numbers ) : Calculate the mean of a list of numbers. return sum ( numbers ) /
def calculatemeannumbers:
Calculate the mean of a list of numbers."""
return sumnumbers lennumbers
def calculatemediannumbers:
Calculate the median of a list of numbers."""
numbers.sort
n lennumbers
#this line calculates the middle index of list
mid n
#this line checks if the length of the list is even if it is the code then calculates the median as the avg of the
#two middle numbers
if n :
return numbersmid numbersmid
else:
return numbersmid
def calculatemodenumbers:
Calculate the mode of a list of numbers."""
frequency
for number in numbers:
frequencynumber frequency.getnumber
maxfreq maxfrequencyvalues
modes key for key, val in frequency.items if val maxfreq
if lenmodes lennumbers:
return None # If all numbers are unique, no real mode
return modes
def calculateskewnessnumbers:
Calculate the skewness of a list of numbers."""
mean calculatemeannumbers
n lennumbers
m sumx mean for x in numbers n
m sumx mean for x in numbers n
if m:
return
skewness mm
return skewness
def main:
marks
while True:
entry inputEnter marks separated by commas or one at a time type 'done' when finished:
if entry.lower 'done':
if lenmarks:
printPlease enter at least two numbers."
continue
break
try:
# Check if multiple marks were entered
if in entry:
newmarks intxstrip for x in entry.split
else:
newmarks intentrystrip
marks.extendnewmarks
except ValueError:
printInvalid input. Please enter only numbers."
continue
while True:
print
Menu:"
print Print the mean of the numbers"
print Print the median of the numbers"
print Print the mode of the numbers"
print Print the skewness of the numbers"
print Enter a NEW set of numbers"
print Add more numbers to the current list"
print Exit the application"
choice inputChoose an option:
if choice :
print
Mean: calculatemeanmarks
elif choice :
print
Median: calculatemedianmarks
elif choice :
moderesult calculatemodemarks
if moderesult is None:
print
No mode, all values are unique."
else:
print
Mode: moderesult
elif choice :
print
Skewness calculateskewnessmarks
elif choice :
marks # Reset the list
continue
elif choice :
continue #Just continue to add more numbers
elif choice :
print
Exiting the program."
break
else:
print
Invalid choice. Please enter a number between and
# Check if we need to continue after adding more numbers
if choice :
newentries input
Enter new marks separated by commas:
try:
newmarks intxstrip for x in newentries.split
marks.extendnewmarks
except ValueError:
print
Invalid input. Please enter only numbers."
if namemain:
main
In this code the print Print the skewness of the numbers"
print Enter a NEW set of numbers"
print Add more numbers to the current list"
doesnt work correctly and it just show the menu again please fix the code to make it show those options work as intended im pretty stuck on it
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started