Hello, everyone. I am taking a beginning python class and was wondering if anyone could help me out? We are writing a program that generates 100 random numbers (between 1 and 1000), and keeps a count of how many of those random numbers are even and how many are odd. We are to use a for loop and a Boolean function, is_even, which may not include any calls to input or print. This is what I have so far for my is_even function:
def is_even(number):
# Determines if the number is odd or even.
if (number % 2) == 0:
status = True
else:
status = False
# Returns status as True or False
return status`
This is what I have for may main function:
def main():
# explain program
print ('This program will generate 100 random numbers between 1 and 1000.')
# Executes random numbers in the range 1 to 100
number = random.randint(100)
# Calls is_even function
is_even(number)
#
for count in range(1, 100):
if is_even (number):
status = True
print ('The positive number count is:', number)
else:
status = False
print ('The odd number count is: ', number)
I am having some issues getting the whole thing to work:
import random
def main():
# explain program
print ('This program will generate 100 random numbers between 1 and 1000.')
# Executes random numbers in the range 1 to 100
number = random.randint(100)
# Calls is_even function
is_even(number)
#
for count in range(1, 100):
if is_even (number):
status = True
print ('The positive number count is:', number)
else:
status = False
print ('The odd number count is: ', number)
def is_even(number):
# Determines if the number is odd or even.
if (number % 2) == 0:
status = True
else:
status = False
# Returns status as True or False
return status
main()
I know I probabaly need some variables at this point:
count
number
is_even
is_odd
Any assistance is appreciated.