Question

Write a program in python that generates X random integers Num. Num is a random number...

Write a program in python that generates X random integers Num.

Num is a random number between 20 to 50.

X is a random number between 10 to 15.

Calculate and show the Smallest, Largest, Sum, and Average of those numbers.

You are not allowed to use Python functions sample(), min(), max(), average(), sort(), sorted()!!

HINTs: to find Smallest....

1) X is a random number between 10 to 15... for example 11...this determines how many times the loop will happen

2) Make the Smallest number equal to the first random number of 20 to 50

3) Compare if the rest of the random numbers between 20 to 50 are less than Smallest...if a number is LESS than Smallest, Smallest equals that number

Sample Run:

Generating 11 random numbers (11 is a random number between 10 to 15)...

...11 Random Numbers between 20 to 50: 26, 23, 48, 32, 44, 21, 32, 20, 49, 48, 34

Sum = 377

Average = 377 / 11 = 34.3

Smallest = 21

Largest = 49

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

import random

#getting random value of X
X = random.randint(10,15)
#numbers list which will store all the random numbers
numbers = []
#getting X random numbers
for i in range(X):
numbers.append(random.randint(20,50))
#printing the numbers
print('{} numbers generated {} is a number generated in the range 10 to 15'.format(str(X),str(X)))
print('{} Random Numbers generated in the range 20 to 50: '.format(str(X)))
print(numbers)
#getting sum, max, min, average from the list
addition = 0
highestNum = numbers[0]
lowestNum = numbers[0]
#traversing the list
for i in numbers:
#adding all numbers
addition += i
#getting the max and the min number
if(i<lowestNum):
lowestNum = i
if(i>highestNum):
highestNum = i
#printing the calculated values
print('\nSum: ',addition)
print('Average: ',round((addition/X),2))
print('Smallest: ',lowestNum)
print('Largest: ',highestNum)

____________________________________________

CODE IMAGES AND OUTPUT:

In [17]: 5 9 1 import random 2 3 #getting random value of x 4 x = random.randint(10,15) #numbers list which will store all th16 highestNum = numbers [0] 17 lowestNum = numbers [0] 18 #traversing the list 19 for i in numbers: 20 #adding all numbers 21

_____________________________________________________

Feel free to ask any questions in the comments section

Thank You!

Add a comment
Know the answer?
Add Answer to:
Write a program in python that generates X random integers Num. Num is a random number...
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
  • Write a python program that generates a list of 50 random numbers. The program should display...

    Write a python program that generates a list of 50 random numbers. The program should display (with labels) the sum, average, largest, and smallest of the list along with the list before and after sorting. Bonus: Find the mode (if any)

  • (+30) Provide a python program which will Populate an array(list) of size 25 with integers in...

    (+30) Provide a python program which will Populate an array(list) of size 25 with integers in the range -100 (negative 100)   to +100 inclusive Display the array and its length (use the len function) Display the average of all the integers in the array Display the number of even integers (how many) Display the number of odd integers (how many) Display the number of integers > 0   (how many) Display the number of integers < 0   (how many) Display the...

  • PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv Write a program that generates two random...

    PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv Write a program that generates two random integer numbers between 1 and 100. Then, print out the numbers between the two randomly generated ones using a while loop. The output is shown below. Output: a) start:4, end:14 4 5 6 7 8 9 10 11 12 13 14 b) start:15, end:20 15 16 17 18 19 20

  • A. Create a java program that generates 1000 random integers. Write the 1000 random integers to...

    A. Create a java program that generates 1000 random integers. Write the 1000 random integers to a file using the Formatter class. B. Create a second java program that opens the file with the 1000 integers using the Scanner class. Read in the integers and find and print out the largest, smallest and the average of all 1000 numbers. C. Repeat A from above but use the BufferedWriter class B. Repeat B from above but use the BufferedReader class.

  • Write a Python program stored in a file q2.py that asks for a starting number and...

    Write a Python program stored in a file q2.py that asks for a starting number and an ending number, and then prints all the Fibonacci numbers between them (and including the starting and ending numbers, if they are also Fibonacci numbers). Each Fibonacci number, must be separated by a space. Example: Enter starting number : 5 Enter ending number : 500 10 Fibonacci numbers between 5 and 500 are : 5 8 13 21 34 55 89 144 233 377

  • In Python 3, Write a program that reads a set of floating-point values. Ask the user...

    In Python 3, Write a program that reads a set of floating-point values. Ask the user to enter the values, then print: The number of values entered. The smallest of the values The largest of the values. The average of the values. The range, that is the difference between the smallest and largest values. If no values were entered, the program should display “No values were entered” The program execution should look like (note: the bold values are sample user...

  • Please use Python for this program Random Number File Writer Write a program that writes a...

    Please use Python for this program Random Number File Writer Write a program that writes a series of random numbers to a file. Each random number should be in the range 1 through 500. The program should let the user specify how many random numbers to put into the file. The name of the file to write to should be 'random.txt'. Submit the random.txt file generated by your program with the assignment. Sample program execution: Python 3.4.3 Shell Eile Edit...

  • please write in python Write a program that asks for beginning and ending number. The program...

    please write in python Write a program that asks for beginning and ending number. The program generates a set of 20 random numbers between the numbers and displays a count of each number generated. Sample output Enter starting and ending number separated by comma: 5, 25 5 occurs 2 times 7 occurs 1 time 8 occurs 1 time 10 occurs 2 times 12 occurs 1 time 13 occurs 2 time 15 occurs 5 times 16 occurs 1 time 20 occurs...

  • *IN PYTHON* (Count single digits) Write a program that generates 1,000 random integers between 0 and...

    *IN PYTHON* (Count single digits) Write a program that generates 1,000 random integers between 0 and 9 and displays the count for each number. (Hint: Use a list of ten integers, say counts, to store the counts for the number of 0s, 1s, ..., 9s.) Rubric 5 pts: Proper use of list to count occurrences of numbers 5 pts: Proper calculations of counts 5 pts: Proper output Note: No software dev plan or UML required

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

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
ADVERTISEMENT