Question

In: Computer Science

(+30) Write a python program that generates four random between -50 and +50 using python’s random...

(+30) Write a python program that generates four random between -50 and +50 using python’s random number generator (RNG) see the following code (modify as needed )

import random
a = 10 # FIX
b =100 # FIX
x = random.randint(a,b) # (1) returns an integer a <= x <= b

# modify a and b according to the lab requirement
print('random integer == ', x)

and displays

  1. the four integers
  2. The maximum integer
  3. The minimum integer
  4. The number of even integers (if x %2 == 0 then x is even)
  5. The number of odd integers
  6. The number of integers greater than -25 but less than 25
  7. The number of positive integers
  8. The number of negative integers
  9. The average of the smallest and largest integers
  10. The average of all four integers

EXAMPLE OUTPUT

If the RNG generated the four integers 22 -8 17 -5 then display

  1. The integers are 22 -8 17 -5
  2. The maximum integer is 22
  3. The minimum integer is -8
  4. The number of even integers is 2
  5. The number of odd integers is 2
  6. The number of integers greater than -25 but less than 25 is 4
  7. The number of positive integers 2
  8. The number of negative integers   2
  9. The average of the smallest and largest integers 7.0
  10. The average of the four integers is 6.5

Solutions

Expert Solution

import random
a = -50 # FIX
b = 50 # FIX
x=[]
for i in range(4):
x.append(random.randint(a,b))
print("The integers are ", end ="")
for i in range(4):
print(x[i], end =" ")
print()
maximum=x[0]
minimum=x[0]
count=0
gc=0
p=0
avg4=0
for i in range(4):
if(maximum<x[i]):
maximum=x[i]
if(minimum>x[i]):
minimum=x[i]
if(x[i]%2==0):
count=count+1
if(x[i]>-25 and x[i]<25):
gc=gc+1
if(x[i]>=0):
p=p+1;
avg4=avg4+x[i]

avg=(maximum+minimum)/2

print("The maximum integer is",maximum)
print("The minimum integer is",minimum)
print("The number of even integers is",count)
print("The number of odd integers is",4-count)
print("The number of integers greater than -25 but less than 25 is",gc)
print("The number of positive integers",p)
print("The number of negative integers ",4-p)
print("The average of the smallest and largest integers",avg)
print("The average of the four integers is ",avg4/4)


Related Solutions

(+30) Write a python program that generates four random between -50 and +50 using python’s random...
(+30) Write a python program that generates four random between -50 and +50 using python’s random number generator (RNG) see the following code (modify as needed ) import random a = 10 # FIX b =100 # FIX x = random.randint(a,b) # (1) returns an integer a <= x <= b # modify a and b according to the lab requirement print('random integer == ', x) and displays 1. the four integers 2. The maximum integer 3. The minimum integer...
Write a program that generates a random number between 1 and 50 and asks the user...
Write a program that generates a random number between 1 and 50 and asks the user to guess it. As a hint, it tells the user how many divisors it has, (excluding 1 and the number itself). Each time the user makes a wrong guess, it displays "Wrong" and says if the guess was too low or too high, until the user gets it right, in which case it says "Right" and says how many trials it took to guess...
Write a Python program which generates a random number between 0 and 24 inclusive and that...
Write a Python program which generates a random number between 0 and 24 inclusive and that print out: • the double of the random number if the random number is greater than 12, • the triple of the random number if it is equal to 12 • and the quadruple of the random number if it is less than 12
Here is my assignment: Write a program that generates a random number between 1 and 50...
Here is my assignment: Write a program that generates a random number between 1 and 50 and asks the user to guess it. As a hint, it tells the user how many divisors it has, (excluding 1 and the number itself). Each time the user makes a wrong guess, it displays "Wrong" and says if the guess was too low or too high, until the user gets it right, in which case it says "Right" and says how many trials...
Create a program that generates random number between 0 and 50 and puts them into a...
Create a program that generates random number between 0 and 50 and puts them into a linked list. When it generates 49, instead of adding it to the list, it prints the list, freeing each node and then exits. Submit your .c file
Random Number Guessing Game (python) *use comments Write a program guess.py that generates a random number...
Random Number Guessing Game (python) *use comments Write a program guess.py that generates a random number in the range of 1 through 20, and asks the user to guess what the number is. If the user's guess is higher than the random number, the program should display "Too high, try again." If the user's guess is lower than the random number, the program should display "Too low, try again." If the user guesses the number, the application should congratulate the...
Write a program in C++ coding that generates a random number between 1 and 500 and...
Write a program in C++ coding that generates a random number between 1 and 500 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” The program should use a loop that repeats until the user correctly guesses the random number. Count the number...
C++. Write a program that generates a random number between 5 and 20 and asks the...
C++. Write a program that generates a random number between 5 and 20 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display Too high. Try again. If the user’s guess is lower than the random number, the program should display Too low, Try again. The program should use a loop that repeats while keeping a count of the number of guesses the user makes until...
Write a program that generates a random number between 1 and 100 and asks the user...
Write a program that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” The program should use a loop that repeats until the user correctly guesses the random number. Your program should also keep a...
Random Number Guessing Game Write a program in C++ that generates a random number between 1...
Random Number Guessing Game Write a program in C++ that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high. Try again.” If the user’s guess is lower than the random number, the program should display “Too low. Try again.” The program should use a loop that repeats until the user correctly guesses the random number....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT