Question

In: Computer Science

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

Solutions

Expert Solution

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:-


Related Solutions

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...
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....
Random Number Guessing Game C++. Write a program that generates a random number between 5 and...
Random Number Guessing Game 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...
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
(+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...
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...
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...
*Write in C* Write a program that generates a random Powerball lottery ticket number . A...
*Write in C* Write a program that generates a random Powerball lottery ticket number . A powerball ticket number consists of 5 integer numbers ( between 1-69) and One power play number( between 1-25).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT