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
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...
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
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.
Exercise 3 – Strings Using a function Write a program that prompts the user to enter...
Exercise 3 – Strings Using a function Write a program that prompts the user to enter two inputs: some text and a word. The program outputs the starting indices of all occurrences of the word in the text. If the word is not found, the program should output “not found”. Example1: Input1: my dog and myself are going to my friend Input2: my Output: 0 11 31 Example 2: Input1: Programming is fun Input 2: my Output: not found
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT