Learn Before
Having Fun with Conditional Statements in Python
The random.randint function creates a random integer between 1 and 6, as if throwing a single dice. If your number is 6, the string "Hurray! You win $5" is printed. If your number is 5, the string "Oh! You win nothing in this round. 6 is the winning number; try again" is printed. Otherwise, the string "Oh no! You lose" is printed.
import random
x = random.randint (1, 6)
print (x, "is your random number ...")
if x == 6:
print ("Hurray! You win $5")
elif x == 5:
print ("Oh! You win nothing in this round. 6 is the winning number; try again")
else:
print ("Oh no! You lose (°_°)")
0
1
Tags
Python Programming Language
Data Science
Related
Having Fun with Conditional Statements in Python
Python Standard Library
BioPython
BioPython Tutorial
Bioinformatics Textbook
Five Cool Things You Can Do with Python
Thing You Can Do with Python
Python Program to Make a Simple Calculator
Python Program to Display Calendar
Python Program to Create Pyramid Patterns
Python Program to Solve Quadratic Equations