Question

This is in python. I need to ask the user to enter some numbers, average, min,...

This is in python. I need to ask the user to enter some numbers, average, min, max, and sort them in numerical order. I also have to check that the user actually entered a number and if they didn't to just skip over that input but still execute based on the numbers they did enter. This is what I have so far.

def randomList(userInput):

    while True:
        userInput = eval(input("Enter some numbers:"))
        randomList = []
        randomList.append(userInput)
        return sum(randomList)/len(randomList)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code is commented and variables are named accordingly.

See code screenshot for indentation. It is important in python.

Code:

# input the numbers
userInput = input("Enter space seperated numbers: ")
# creating list of numbers
userInput = userInput.split(" ")
randomList=[]
# appending numbers to list
for num in userInput:

# try is used to handle if number is not entered
try:

# converting to float
num= float(num)
randomList.append(num)

except:

pass

n= len(randomList)
# if some numbers are entered
if n!=0:

mini= randomList[0]
maxi= randomList[0]
average=0
for num in randomList:

mini= min(mini,num)
maxi= max(maxi,num)
average+=num

average/=n
#sorting
randomList.sort()
print("average is "+str(average))
print("min is "+str(mini))
print("max is "+str(maxi))
print("sorted numbers are "+str(randomList))

else:

print("No numbers entered")

Code screenshot:

Sample run:

Add a comment
Know the answer?
Add Answer to:
This is in python. I need to ask the user to enter some numbers, average, min,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • for python-3 I want to prompt the user to enter their first name and then Call...

    for python-3 I want to prompt the user to enter their first name and then Call the is_field_blank function to see if nothing was entered.and If nothing was entered i want it to display the following message "First Name must be Entered" and then re-prompt the user to enter the first name. I want it to do this repeatedly until the user enters a first name. this is what i have so far def main():     yourFirst = input("What is...

  • JAVA Ask the user for integers. If the user did not enter an integer, ask again....

    JAVA Ask the user for integers. If the user did not enter an integer, ask again. (Type Safe Input) Keep a running total of the intergers entered (sum). Once the user enters 0, stop looping. Print the sum of all the numbers. Do not use try-catch. EXAMPLE OUTPUT: Enter an integer, 0 to stop> [fasdfsa] Invalid input. Enter an integer, 0 to stop> [231.342] Invalid input. Enter an integer, 0 to stop> [1] Enter an integer, 0 to stop> [2]...

  • Create two java programs. The first will ask the user to enter three integers. Once the...

    Create two java programs. The first will ask the user to enter three integers. Once the three integers are entered, ask the user to enter one of three functions. The “average” if they want the average of the three numbers entered, enter “min” if they want the minimum and “max” if they want the maximum. Display the answer. Ask the user if they want to calculate another function for the three numbers. If so, loop and ask what function they...

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

  • IN PYTHON Write a function that does not receive parameters but the user must enter numbers...

    IN PYTHON Write a function that does not receive parameters but the user must enter numbers until they give him a 0. While the user does not give him a 0, the program must show how many numbers were entered, the sum of these numbers and the average (not counting the 0) example: 16 4 42 8 23 15 0 output: numbres = 6 sum = 108 average = 18.0

  • 1. Ask the user to enter the number in binary format. 2. Check to see that...

    1. Ask the user to enter the number in binary format. 2. Check to see that the number entered is actually in binary format (starts with a '1' and only has '0's and '1's). - If the user input is something that is not correct, then ask the user to re-enter the number. Make sure you respond appropriately so the user has some idea of what went wrong.

  • In the python: Note 1: You may not use these python built-in functions: sorted(), min(), max(),...

    In the python: Note 1: You may not use these python built-in functions: sorted(), min(), max(), sum(), pow(), zip(), map(), append(), count() and counter(). For questions 1, 2 and 4: Ask the user to enter the size of a list. Fill the list with random numbers 0-9 and print the list. 1- (8 points) luckyNumbers.py: Find the sum of the numbers in a list, except the number 7 is considered unlucky, so we ignore it and do not include 7's...

  • Create a Python Program that will ask the user for a password (use input) Verify that...

    Create a Python Program that will ask the user for a password (use input) Verify that the password meets the following conditions: -must be 12 characters long -must have uppercase and lowercase -must contain at least 1 special character (!~#$%^&*{}+_) -must be a mix of numbers and letters You must do this only using regular expressions so for instance this will not be accepted if len(password) <12: At the end of the program tell the user their password is ok...

  • Create a Python Program that will ask the user for a password (use input) Verify that...

    Create a Python Program that will ask the user for a password (use input) Verify that the password meets the following conditions: -must be 12 characters long -must have uppercase and lowercase -must contain at least 1 special character (!~#$%^&*{}+_) -must be a mix of numbers and letters You must do this only using regular expressions so for instance this will not be accepted if len(password) <12: At the end of the program tell the user their password is ok...

  • USING PYTHON - Write a program that calls a function that prompts the user to enter...

    USING PYTHON - Write a program that calls a function that prompts the user to enter a real number. The function should verify that the user entered a valid real number, and should prompt the user to re-enter any invalid input. After a valid real number has been entered, the function should return the number as a number. To test your function, from a main function, call the function two separate times and print the sum of the two numbers...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT