Jump to content

How to make an amount of variables in python by the user input

Going_AFK
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.
    


 

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

Link to comment
Share on other sites

Link to post
Share on other sites

So what is it are you exactly looking to do?  Take some n amount of inputs from the user and then take the average?

Link to comment
Share on other sites

Link to post
Share on other sites

Are you trying to find the mean average deviation of a dataset? That's what I understood from the question.

Link to comment
Share on other sites

Link to post
Share on other sites

Use a list, you can add an arbitrary amount of values to it.

 

To find the average you don't need to record evry input separately though, just add them to the same variable as they are inserted and use the final value to work out the average.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

input = raw_input("List your numbers, seperated by spaces# ").split(" ") 
print input

 

Link to comment
Share on other sites

Link to post
Share on other sites

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.
    


 

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×