Question: I am trying to write a program in python that has a main() function and a void function named numbers() that takes no arguments and
I am trying to write a program in python that has a main() function and a void function named numbers() that takes no arguments and returns the variable used for the total. The numbers function generates 20 random integers, it is required to use the random.randint method to generate these numbers. The range would be 8 to 59 inclusive, (duplicates are okay), and prints them all on one line separated by spaces. A loop is required for this, and the loop should also total up the integers so the sum can be displayed when the loop ends. The main() function calls the numbers() function. Here is what I have so far, but it only displays 1 number and not the 20 that should be displayed. I need some guidance on what I'm doing wrong. Thank you! import random
def numbers(): #function that generates 20 random integers #prints on single line and prints the total sum #set sum to 0 total=0
for number in range(20): number = random.randint(8, 59) print (number, end='') #add all numbers for sum total+=number print (' The total is ',total) def main(): #call the function numbers() main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
