In: Computer Science
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
Program code to copy:-
# This program generates a random number between 0 and 24.
# And 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
#Importing the random module for using randint() to generate random number
import random
def main():
#Generating random number between 0 to 24
number = random.randint(0, 24)
#Printing generated random number
print('The random number generated: ', number)
# Calculating & printing double or triple or quadruple of
# generated random number based on the given condition.
if number > 12:
result = 2*number; #Calculating double
print('The double of the random number: ', result)
elif number == 12:
result = 3*number; #Calculating triple
print('The Triple of the random number: ', result)
elif number < 12:
result = 4*number; #Calculating quadruple
print('The quadruple of the random number: ', result)
main() #calling main function
Screenshot of Program:-
Screenshot of output:-