Write a program in python 3 that uses a custom function to generate a specified number of random integers in a specified range. This custom function should take three arguments; the number of integers to generate, the lower limit for the range, and the upper limit for the range. Values for these arguments should be entered by the user in main. The custom function should display the random integers on one line separated by single spaces. The function should also report how many numbers were even and how many were odd. Finally, the function should calculate the total of the random integers and return this total back to main where it will be printed. User inputs in main are shown in blue. Sample Output How many integers are to be generated 8 Enter the lowest integer desired 10 Enter the highest integer desired 20 16 14 19 20 12 15 18 18 6 evens and 2 odds were generated The total of those 8 random numbers is 132
import random n = int(input("How many integers are to be generated ")) low = int(input("Enter the lowest integer desired ")) high = int(input("Enter the highest integer desired ")) evens = 0 odds = 0 total = 0 for i in range(n): val = random.randint(low,high) if(val%2==0): evens += 1 else: odds += 1 total += val print(val,end=' ') print() print(evens,"evens and",odds,"odds were generated") print("The total of those",n,"random numbers is",total)
Get Answers For Free
Most questions answered within 1 hours.