Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def calculate _ mean ( numbers ) : Calculate the mean of a list of numbers. return sum ( numbers ) /

def calculate_mean(numbers):
"""Calculate the mean of a list of numbers."""
return sum(numbers)/ len(numbers)
def calculate_median(numbers):
"""Calculate the median of a list of numbers."""
numbers.sort()
n = len(numbers)
#this line calculates the middle index of list
mid = n //2
#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 %2==0:
return (numbers[mid -1]+ numbers[mid])/2
else:
return numbers[mid]
def calculate_mode(numbers):
"""Calculate the mode of a list of numbers."""
frequency ={}
for number in numbers:
frequency[number]= frequency.get(number,0)+1
max_freq = max(frequency.values())
modes =[key for key, val in frequency.items() if val == max_freq]
if len(modes)== len(numbers):
return None # If all numbers are unique, no real mode
return modes
def calculate_skewness(numbers):
"""Calculate the skewness of a list of numbers."""
mean = calculate_mean(numbers)
n = len(numbers)
m3= sum((x - mean)**3 for x in numbers)/ n
m2= sum((x - mean)**2 for x in numbers)/ n
if m2==0:
return 0
skewness = m3/(m2**1.5)
return skewness
def main():
marks =[]
while True:
entry = input("Enter marks separated by commas or one at a time (type 'done' when finished): ")
if entry.lower()== 'done':
if len(marks)<2:
print("Please enter at least two numbers.")
continue
break
try:
# Check if multiple marks were entered
if ',' in entry:
new_marks =[int(x.strip()) for x in entry.split(',')]
else:
new_marks =[int(entry.strip())]
marks.extend(new_marks)
except ValueError:
print("Invalid input. Please enter only numbers.")
continue
while True:
print("
Menu:")
print("1. Print the mean of the numbers")
print("2. Print the median of the numbers")
print("3. Print the mode of the numbers")
print("4. Print the skewness of the numbers")
print("5. Enter a NEW set of numbers")
print("6. Add more numbers to the current list")
print("7. Exit the application")
choice = input("Choose an option: ")
if choice =='1':
print("
""Mean:", calculate_mean(marks))
elif choice =='2':
print("
""Median:", calculate_median(marks))
elif choice =='3':
mode_result = calculate_mode(marks)
if mode_result is None:
print("
""No mode, all values are unique.")
else:
print("
""Mode:", mode_result)
elif choice =='4':
print("
""Skewness", calculate_skewness(marks))
elif choice =='5':
marks =[] # Reset the list
continue
elif choice =='6':
continue #Just continue to add more numbers
elif choice =='7':
print("
""Exiting the program.")
break
else:
print("
""Invalid choice. Please enter a number between 1 and 7.")
# Check if we need to continue after adding more numbers
if choice =='6':
new_entries = input("
""Enter new marks (separated by commas): ")
try:
new_marks =[int(x.strip()) for x in new_entries.split(',')]
marks.extend(new_marks)
except ValueError:
print("
""Invalid input. Please enter only numbers.")
if __name__=="__main__":
main()
In this code the print("4. Print the skewness of the numbers")
print("5. Enter a NEW set of numbers")
print("6. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

2 What are the steps that can aid effective communication?

Answered: 1 week ago