Skip to content

Commit 7929824

Browse files
updated
1 parent 28ca195 commit 7929824

3 files changed

Lines changed: 126 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import random
2+
3+
options = ("rock", "paper", "scissors" )
4+
player = None
5+
computer = random.choice(options)
6+
7+
running = True
8+
9+
while running:
10+
while player not in options:
11+
player = input("rock, paper, scissors: ").lower()
12+
if player == computer:
13+
print("Tie!")
14+
elif player == "rock":
15+
if computer == "paper":
16+
print("You lose!", computer, "covers", player)
17+
else:
18+
print("You win!", player, "smashes", computer)
19+
20+
elif player == "paper":
21+
if computer == "scissors":
22+
print("You lose!", computer, "cut", player)
23+
else:
24+
print("You win!", player, "covers", computer)
25+
26+
elif player == "scissors":
27+
if computer == "rock":
28+
print("You lose...", computer, "smashes", player)
29+
else:
30+
print("You win!", player, "cut", computer) if computer == "" else ""
31+
else:
32+
print("Invalid choice. Please choose rock, paper, or scissors.") if computer == "" else ""
33+
play_again = input("Play again? (yes/no): ").lower()
34+
if play_again != "yes":
35+
running = False
36+
player = None
37+
computer = random.choice(options)

30-dice-roller-program

Whitespace-only changes.

30-dice-roller-program/main.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import random
2+
3+
# 🎲 Dice Roller Program
4+
5+
# ASCII art for dice faces
6+
dice_art = {
7+
1: ("┌─────────┐",
8+
"│ │",
9+
"│ ● │",
10+
"│ │",
11+
"└─────────┘"),
12+
13+
2: ("┌─────────┐",
14+
"│ ● │",
15+
"│ │",
16+
"│ ● │",
17+
"└─────────┘"),
18+
19+
3: ("┌─────────┐",
20+
"│ ● │",
21+
"│ ● │",
22+
"│ ● │",
23+
"└─────────┘"),
24+
25+
4: ("┌─────────┐",
26+
"│ ● ● │",
27+
"│ │",
28+
"│ ● ● │",
29+
"└─────────┘"),
30+
31+
5: ("┌─────────┐",
32+
"│ ● ● │",
33+
"│ ● │",
34+
"│ ● ● │",
35+
"└─────────┘"),
36+
37+
6: ("┌─────────┐",
38+
"│ ● ● │",
39+
"│ ● ● │",
40+
"│ ● ● │",
41+
"└─────────┘")
42+
}
43+
44+
def roll_dice(num_dice):
45+
"""Roll the specified number of dice and display the results"""
46+
if num_dice < 1:
47+
print("Please enter a valid number of dice (1 or more)")
48+
return
49+
50+
results = []
51+
for _ in range(num_dice):
52+
results.append(random.randint(1, 6))
53+
54+
# Display dice art
55+
print("\n" + "="*50)
56+
print(f"Rolling {num_dice} dice...")
57+
print("="*50 + "\n")
58+
59+
# Display all dice side by side
60+
for line_index in range(5):
61+
line = ""
62+
for result in results:
63+
line += dice_art[result][line_index] + " "
64+
print(line)
65+
66+
print("\n" + "="*50)
67+
print(f"Results: {results}")
68+
print(f"Total: {sum(results)}")
69+
print("="*50 + "\n")
70+
71+
def main():
72+
print("🎲 Welcome to the Dice Roller Program! 🎲\n")
73+
74+
while True:
75+
try:
76+
num_dice = input("How many dice would you like to roll? (or 'q' to quit): ").strip()
77+
78+
if num_dice.lower() == 'q':
79+
print("Thanks for playing! Goodbye! 👋")
80+
break
81+
82+
num_dice = int(num_dice)
83+
roll_dice(num_dice)
84+
85+
except ValueError:
86+
print("Please enter a valid number or 'q' to quit\n")
87+
88+
if __name__ == "__main__":
89+
main()

0 commit comments

Comments
 (0)