Question

In: Computer Science

Python program A number game machine consists of three rotating disks labelled with the numbers 0...

Python program

A number game machine consists of three rotating disks labelled with the numbers 0 to 9 (inclusive). If certain combinations of numbers appear when the disks stop moving, the player wins the game.

The player wins if

  • the first and third numbers are the same, and the second number is less than 5, or
  • all three numbers are the same, or
  • the sum of the first two numbers is greater than the third number;

otherwise the player loses.

Write a Python program to simulate this number game by randomly generating 3 integer values between 0 and 9 (inclusive), and printing whether the player has won or lost the game.

To randomly generate a number between and including 0 and 9, use the randintmethod from random library module. For example, x = random.randint(1,100)will automatically generate a random integer between 1 and 100 (inclusive) and store it in x.

Sample output 1:

Random numbers: 2 3 5
You lose.

Sample output 2:

Random numbers: 7 7 0
You win!

Solutions

Expert Solution

#importing random to access randint() method
import random

#randomly generating 3 numbers between 0 and 9
x = random.randint(0,9)
y = random.randint(0,9)
z = random.randint(0,9)

#printing generated numbers
print(x,y,z)

# Assuming that player lose
win = False;

#the first and third numbers are the same, and the second number is less than 5
if x==z and y<5:
win = True

# all three numbers are the same
elif x==y and y==z:
win = True

# the sum of the first two numbers is greater than the third number
elif x+y>z:
win = True

# if win is True, Player wins
if(win):
print("You win!")

# otherwise lose
else:
print("You lose.")

INDENTED CODE SCREENSHOT:

OUTPUT:

Run1:

Run2:


Related Solutions

Write a program in Python that will print first 100 numbers of the following series: 0,...
Write a program in Python that will print first 100 numbers of the following series: 0, 1, 1, 2, 3, 5, 8……..
PYTHON Exercise 5. Guess the number 1. Develop a “Guess the number” game. Write a program...
PYTHON Exercise 5. Guess the number 1. Develop a “Guess the number” game. Write a program that comes up with a random number and the player has to guess it. The program output can be like this: I am thinking of a number between 1 and 20. Take a guess. 10 Your guess is too low. Take a guess. 15 Your guess is too low. Take a guess. 17 Your guess is too high. Take a guess. 16 Good job!...
In Python please:  Number the Lines in a File: Create a program that adds line numbers to...
In Python please:  Number the Lines in a File: Create a program that adds line numbers to a file. The name of the input file will be read from the user, as will the name of the new file that your program will create. Each line in the output file should begin with the line number, followed by a colon and a space, followed by the line from the input file.
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...
“Triangle Guessing” game in Python The program accepts the lengths of three (3) sides of a...
“Triangle Guessing” game in Python The program accepts the lengths of three (3) sides of a triangle as input . The program output should indicate if the triangle is a right triangle, an acute triangle, or an obtuse triangle. Make sure each side of the triangle is a positive integer. Use try/except for none positive integer input. validating the triangle. That is the sum of the lengths of any two sides of a triangle is greater than the length of...
The figure shows three rotating, uniform disks that are coupled by belts. One belt runs around...
The figure shows three rotating, uniform disks that are coupled by belts. One belt runs around the rims of disks A and C. Another belt runs around a central hub on disk A and the rim of disk B. The belts move smoothly without slippage on the rims and hub. Disk A has radius R; its hub has radius 0.439R; disk B has radius 0.240R; and disk C has radius 1.69R. Disks B and C have the same density (mass...
Create this on Python Write a program that asks for three numbers. Check first to see...
Create this on Python Write a program that asks for three numbers. Check first to see that all numbers are different. If they’re not different, then exit the program. Otherwise, display the largest number of the three. Outputs: - Enter the first number: 4 - Enter the second number: 78 - Enter the third number: 8 (The largest number is 78.) Tasks - Complete the algorithm manually without using any built-in functions to find the largest number on list. -...
Given n. Write a program in PYTHON to Generate all numbers with number of digits equal...
Given n. Write a program in PYTHON to Generate all numbers with number of digits equal to n, such that the digit to the right is greater than the left digit (ai+1 > ai). E.g. if n=3 (123,124,125,……129,234,…..789)
In this python program , you are to build a trivia game. The game should present...
In this python program , you are to build a trivia game. The game should present each question – either in order or randomly – to the player, and display up to four possible answers. The player is to input what they believe to be the correct answer.   The game will tell the player if they got it right or wrong and will display their score. If they got it right, their score will go up. If they got it...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT