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

my work: # importing "random" for random operations import random # importing mean() from statistics import mean a=random.randint(-50,50) b=random.randint(-50,50) c=random.randint(-50,50) d=random.randint(-50,50) print("1st random number is "+str(a)) print("2nd random number is "+str(b)) print("3rd random number is "+str(c)) print("4th random number is "+str(d)) list1=[a,b,c,d] print("The maximum integer: ",max(list1)) print("The minimum integer: ",min(list1)) odds = [] # list to keep track of odd evens = [] # list to keep track of evens # even and odds calculations if a % 2 == 0: evens.append(a) else: odds.append(a) if b % 2 == 0: evens.append(b) else: odds.append(b) if c % 2 == 0: evens.append(c) else: odds.append(c) if d % 2 == 0: evens.append(d) else: odds.append(d) print ("evens are: " , evens) print ("odds are: " , odds) number1=[] if a > -25 & a < 25: number1.append(a) if b > -25 & b < 25: number1.append(b) if c > -25 & c < 25: number1.append(c) if d > -25 & d < 25: number1.append(d) print("The number of integers greater than -25 but less than 25: ", number1) positive = [] negtive = [] if a >= 0: positive.append(a) else: negtive.append(a) if b >= 0: positive.append(b) else: negtive.append(b) if c >= 0: positive.append(c) else: negtive.append(c) if d >= 0: positive.append(d) else: negtive.append(d) print("positive integers are: ", positive) print("negative integers are: ", negtive) avg_s_m = (max(list1) + min(list1)) / 2 print("average of the smallest and largest integers: ", avg_s_m) avg = mean(list1) print("average of all four integers: ", avg)

getting error. line 20 evens.append(a) ^ IndentationError: expected an indented block. please help

Solutions

Expert Solution

if you have any doubts, please give me comment...

# importing "random" for random operations

import random

# importing mean()

from statistics import mean

a = -50

b = 50

list1 = []

for i in range(4):

    num = random.randint(a, b)

    list1.append(num)

print("The integers are "+ ' '.join(map(str, list1)))

minimum = min(list1)

maximum = max(list1)

print("The maximum integer is", minimum)

print("The minimum integer is", maximum)

even_count = 0

odd_count = 0

for num in list1:

    if num%2==0:

        even_count += 1

    else:

        odd_count += 1

print("The number of even integers is",even_count)

print("The number of odd integers is",odd_count)

count_range = 0

for num in list1:

    if num>-25 and num<25:

        count_range += 1

print("The number of integers greater than -25 but less than 25 is", count_range)

positive = 0

negative = 0

for num in list1:

    if num>=0:

        positive += 1

    else:

        negative += 1

print("The number of positive integers", positive)

print("The number of negative integers", negative)

print("The average of the smallest and largest integers", ((minimum+maximum)/2))

print("The average of the four integers is",mean(list1))

Let me know if you have any errors/clarifications. Thank you


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 the four integers The maximum integer The minimum integer The number of...
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