Learn Before
Code

Python if-elif-else Statement Example Using random.randint

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

Updated 2026-06-27

Tags

Python Programming Language

Data Science