How to make an amount of variables in python by the user input
Go to solution
Solved by straight_stewie,
10 hours ago, Going_AFK said:I need this to help me in a task in class I am in the best in the class and I want to be better please can you help me this is for finding the average
Well, here are two types of the three basic averages. I'll leave you to figure out the mode average for yourself (it's easy too)
Mean:
user_sum = 0 count = 0 user_entry = "" while True: try: user_num = input("Please enter the next number") if user_num = "done": break else: user_sum += int(user_num) count += 1 except: print("You did not enter a valid number") average = user_sum / count print(average)
Median:
num_list = [] exit_command = "" while True: try: exit_command = input("Please enter a number") num_list.append(int(exit_command)) except: if exit_command == "done": break else: print("You did not enter a valid number") num_list.sort() print(num_list[len(num_list) // 2]) # There is some argument to be had as to whether you should use the ceiling or the floor.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now