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

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
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)
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
In PYTHON OF JUPIDER NOTEBOOK Write a program that prompts the user to enter his/her nationality...
In PYTHON OF JUPIDER NOTEBOOK Write a program that prompts the user to enter his/her nationality (French/french, Italian/italian, or Spanish/spanish). Then ask his/her name using a prompt message in his/her own language (use Google Translate if you need). After getting the name, again greet him/her using a greeting message in his/her own language. If the user is not from any of the above nationalities just use English to prompt for name and to greet the user. Example 1: Nationality? french...
Write a Flask app in which a Python script prompts the user to enter a string...
Write a Flask app in which a Python script prompts the user to enter a string and then that string, as entered, gets displayed on an otherwise blank HTML file, called output.html. Show the Python/Flask code and the html code of the output.html file, one below the other as part of your answer.
python.Write a python program that prompts the user to enter the year and first day of...
python.Write a python program that prompts the user to enter the year and first day of the year, and displays the first day of each month in the year. For example, if the user entered the year 2020 and 3 for Wednesday, January 1, 2020, your program should display the following output: January 1, 2020 is Wednesday February 1, 2020 is Saturday …… December 1, 2020 is Tuesday
Write a program in PYTHON, using a while loop, that asks the user to enter the...
Write a program in PYTHON, using a while loop, that asks the user to enter the amount that they have budgeted for the month. The program should then prompt the user to enter their expenses for the month. The program should keep a running total. Once the user has finished entering their expenses the program should then display if the user is over or under budget. The output should display the monthly budget, the total expenses and whether the user...
Write a C++ program which prompts the user to enter an integer value, stores it into...
Write a C++ program which prompts the user to enter an integer value, stores it into a variable called ‘num’, evaluates the following expressions and displays results on screen. num+5, num-3, (num+3) – 2, ((num+5)*2 / (num+3)) For performing addition and subtraction, you are allowed to use ONLY the increment and decrement operators (both prefixing and postfixing are allowed). You must remember that using increment/decrement operators changes the original value of a number. Indent your code and include comments for...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT