Question

In: Computer Science

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 range from 0 to 50, but you can use any range you like.

Solutions

Expert Solution

Please check out the code with the output... please do a comment for having any kind of doubt... thank...

please see the comments with the code for better understanding...

import random   #for random function
def Read(fname):     #for reading the data
        f=open(fname)   #opening file
        R=f.read()      #reading whole data as a string
        f.close()       #closing file
        return R    #returning the string
def ptr(list):    #prints the list
        print(list)
def lowest(list):   #prints the lowest element in the list
        print("lowest number in the list is ",min(list))
def highest(list):    #prints the lowest element in the list
        print("Highest number in the list is ",max(list))
def Sum(list):       #prints the sum of elements on the list
        print("Sum = ",sum(list))
        return sum(list)  #returns sum which is required for average
def avg(s,n):    #prints the average of the list
        print("Average is = ",float(s/n))



#start of main

x, y = [int(x) for x in input("Enter two value for range : ").split()]  #taking range of random integer
n=int(input("Enter the number of random integers : ")) #number of random integer
fname=input("Enter the file name : ")    #input file name where to store
f=open(fname,"w+")    #opening file for writing
for i in range(n):
        r=random.randint(x,y)   #generates random number b/w x,y
        f.write("%d "%r)   #writing in file
f.close()  #closing file
R=Read(fname)   #reading the file as a string
list=[]   #declearing a list
s=0    #s is required for calculating each of the number
for i in R:
        if i!=' ':   # if the current index is not a space
                s=s*10+int(i)   #calculating the integer number
        else:
                list.append(s)   #i.e. if it is a space, then one integer is complete. so append it to list
                s=0   #making s=0 again for next element
f.close()   #closing file
ptr(list)   #calling function
lowest(list)
highest(list)
s=Sum(list)
avg(s,n)

output

screen sort of code...


Related Solutions

Write a Python program with correct indentation using functions and mainline logic which prompts the user...
Write a Python program with correct indentation 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,...
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...
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 that prompts the user to enter a list of words and stores...
Write a Python program that prompts the user to enter a list of words and stores in a list only those words whose first letter occurs again within the word (for example, 'Baboon'). The program should display the resulting list..................please explain step by step
Write a program function code in Python that prompts the user to enter the total of...
Write a program function code in Python that prompts the user to enter the total of his/her purchase and add 5% as the VAT. The program should display the total without and with VAT. ( that mean i should ask the user to enter the number of their item " so i think that i should use range" then print the result with and without the VAT )
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)
USE PYTHON. Write a program that prompts the user to enter 5 test scores. The program...
USE PYTHON. Write a program that prompts the user to enter 5 test scores. The program should display a letter grade for each score and the average test score. Hint: Declare local variables under main() program Prompts the user to enter 5 test scores Define a function to calculate the average score: this should accept 5 test scores as argument and return the avg Define a function to determine the letter grade: this should accept a test score as argument...
python programming. Write a program that prompts the user to enter an integer from 0 to...
python programming. Write a program that prompts the user to enter an integer from 0 to 9. The program will check if the input is a positive integer. It displays the correct answer and shows the guess is correct or not. The demos are shown as following.(Hint:1. Use a random math function 2. Use str.isdigit() to check the input)
Write a program in c++ using only if statements that prompts the user to enter an...
Write a program in c++ using only if statements that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1 …., and Saturday is 6) then displays today. Also, prompt the user to enter the number of days after today for a future day and display the future day of the week. The future day can be computed as follows: (today + number of days after today) % 7 Sample run...
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