Question

In: Computer Science

Do it in python please Write a program using functions and mainline logic which prompts the...

Do it in python please

Write a program using functions and mainline logic which prompts the user to enter a number, then generates that number of random integers and stores them in a list. It should then display the following data to back to the user:

  • The list of integers
  • The lowest number in the list
  • The highest number in the list
  • The total sum of all the numbers in the list
  • The average number in the list
  • At a minimum, the numbers should range from 0 to 50, but you can use any range you like.

Helpful hint: don't forget about input validation loops and try/catch exceptional handling. Both are very useful when used in conjunction with functions.

Solutions

Expert Solution

Source Code:

import random

def random_list(n):
rand_list=[]
for i in range(0,n):
rand_list.append(random.randint(0,100))
return rand_list

def getMinimum(lst):
return min(lst)

def getMaximum(lst):
return max(lst)

def getSum(lst):
return sum(lst)

def getAverage(lst):
return sum(lst)/len(lst)

n=int(input("Enter the number of random numbers(must greater than 0):"))
while(n<=0):
print("Sorry please enter valid positive integer.")
n=int(input("Enter the number of random numbers(must greater than 0):"))
lst=random_list(n)
print("Generated Random List =",lst)
lowest=getMinimum(lst)
print("Minimum of List =",lowest)
highest=getMaximum(lst)
print("Maximum of List =",highest)
total_sum=getSum(lst)
print("Sum of the List =",total_sum)
average=getAverage(lst)
print("Average of List =",average)

Sample input and output:


Related Solutions

Write a Python program using functions and mainline logic which prompts the user to enter a...
Write a Python program using functions and mainline logic which prompts the user to enter a number, then generates that number of random integers and stores them in a file. It should then display the following data to back to the user: The list of integers The lowest number in the list The highest number in the list The total sum of all the numbers in the list The average number in the list At a minimum, the numbers should...
PLEASE INCLUDE #FOR EACH LINE EXPLANATION Write a PYTHON PROGRAM that prompts for an integer and...
PLEASE INCLUDE #FOR EACH LINE EXPLANATION Write a PYTHON PROGRAM that prompts for an integer and prints the integer, but if something other than an integer is input, the program keeps asking for an integer. Here is a sample session: Input an integer: abc Error: try again. Input an integer: 4a Error: try again. Input an integer: 2.5 Error: try again. Input an integer: 123 The integer is: 123 Hint: the string isdigit method will be useful to solve this...
Write a program In python of Jupiter notebook (using loops) that prompts the user to enter...
Write a program In python of Jupiter notebook (using loops) that prompts the user to enter his/her favorite English saying, then counts the number of vowels in that (note that the user may type the saying using any combination of upper or lower case letters). Example: Enter your favorite English saying: Actions speak LOUDER than words. Number of wovels: 10
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
(using for loop, parameters, if, else condition only )Python: Write a program that prompts the user...
(using for loop, parameters, if, else condition only )Python: Write a program that prompts the user to enter a positive integer value, and compute the following sequence: • If the value is even, halve it. • If it's odd, multiply by 3 and add 1. • Repeat this process until the value is 1, printing out each value. • Then print out how many of these operations you performed. If the input value is less than 1, print a message...
USING PYTHON ONLY Part 3a: Prime Number Finder Write a program that prompts the user to...
USING PYTHON ONLY Part 3a: Prime Number Finder Write a program that prompts the user to enter in a postive number. Only accept positive numbers - if the user supplies a negative number or zero you should re-prompt them. Next, determine if the given number is a prime number. A prime number is a number that has no positive divisors other than 1 and itself. For example, 5 is prime because the only numbers that evenly divide into 5 are...
Python A program which prompts the user to enter an number which is a integer n...
Python A program which prompts the user to enter an number which is a integer n and creates a tuple where the values are all numbers between 1 and n (both inclusive). Note: you can assume that the integer will always be > 1. Input Result 3 Enter an integer: 3 (1, 2, 3)
Using python Write a program that has 3 functions, named write_to_file, read_from_file, and ask_user. The write_to_file...
Using python Write a program that has 3 functions, named write_to_file, read_from_file, and ask_user. The write_to_file function should have 2 parameters, file_name and data. When called, the function will open a file with the name stored in the file_name variable, write the information stored in data, then close the file. The read_from_file function will have 1 parameter, file_name. When called, the function will open a file with the name stored in the file_name variable, print the contents of the file,...
Write a program which prompts the user for the year of their birth, and which then...
Write a program which prompts the user for the year of their birth, and which then calculates their age (ignoring the month/day). Split the program into `main`, a "prompt for year" function which tests to make sure the user's input is a valid year, and a "calculate age" function which performs the actual calculation. (You can assume the current year is 2017.) for my intro to c++ class
Write a PYTHON program that prompts the user to enter the account’s present value, yearly interest...
Write a PYTHON program that prompts the user to enter the account’s present value, yearly interest rate, and the number of years that the money will be left in the account. The program should pass these values to a function that returns the future value of the account, after the specified number of months. The program should display the accounts’ future value
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT