File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed
Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ '''
2+ Dice Roll Generator
3+ -------------------------------------------------------------
4+ '''
5+
6+
7+ import random
8+ import os
9+
10+
11+ def num_die():
12+ while True:
13+ try:
14+ num_dice = input('Number of dice: ')
15+ valid_responses = ['1', 'one', 'two', '2']
16+ if num_dice not in valid_responses:
17+ raise ValueError('1 or 2 only')
18+ else:
19+ return num_dice
20+ except ValueError as err:
21+ print(err)
22+
23+
24+ def roll_dice():
25+ min_val = 1
26+ max_val = 6
27+ roll_again = 'y'
28+
29+ while roll_again.lower() == 'yes' or roll_again.lower() == 'y':
30+ os.system('cls' if os.name == 'nt' else 'clear')
31+ amount = num_die()
32+
33+ if amount == '2' or amount == 'two':
34+ print('Rolling the dice...')
35+ dice_1 = random.randint(min_val, max_val)
36+ dice_2 = random.randint(min_val, max_val)
37+
38+ print('The values are:')
39+ print('Dice One: ', dice_1)
40+ print('Dice Two: ', dice_2)
41+ print('Total: ', dice_1 + dice_2)
42+
43+ roll_again = input('Roll Again? ')
44+ else:
45+ print('Rolling the die...')
46+ dice_1 = random.randint(min_val, max_val)
47+ print(f'The value is: {dice_1}')
48+
49+ roll_again = input('Roll Again? ')
50+
51+
52+ if __name__ == '__main__':
53+ roll_dice()
You can’t perform that action at this time.
0 commit comments