-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdie_roller.py
More file actions
35 lines (30 loc) · 825 Bytes
/
die_roller.py
File metadata and controls
35 lines (30 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
Project: Dice Roller
Author:Aysha Surook k
Description:
Create a program that simulates rolling dice.
Requirements:
1. Ask the user how many dice they want to roll.
2. Ask the user if they want to roll the dice.
3. If the user enters 'yes', generate random numbers between 1 and 6.
4. Display the result for each dice.
5. If the user enters 'no', exit the program.
6. Handle invalid inputs.
Sample Input:
How many dice to roll: 3
Do you want to roll the dice? (yes/no): yes
Sample Output:
Dice 1: 4
Dice 2: 2
Dice 3: 6
"""
import random
n=int(input("How many dice to roll: "))
choice=input("Do you want to roll the dice? (yes/no): ").lower()
if choice=="yes":
for i in range(n):
print(f"Dice {i+1}: {random.randint(1,6)}")
elif choice=="no":
print("Program exited.")
else:
print("Invalid input.")