Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f72df54

Browse files
Create Dice_Rolling.py
1 parent c0b68a7 commit f72df54

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

‎Dice Rolling Game/Dice_Rolling.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import random
2+
3+
def roll_dice():
4+
return random.randint(1, 6)
5+
6+
def ai_roll():
7+
return roll_dice()
8+
9+
def main():
10+
print("Welcome to Dice Rolling AI!")
11+
12+
while True:
13+
user_input = input("Press 'Enter' to roll the dice or 'q' to quit: ")
14+
if user_input.lower() == 'q':
15+
print("Thanks for playing!")
16+
break
17+
18+
user_roll = roll_dice()
19+
ai_roll_result = ai_roll()
20+
21+
print(f"You rolled: {user_roll}")
22+
print(f"AI rolled: {ai_roll_result}")
23+
24+
if user_roll > ai_roll_result:
25+
print("Congratulations! You won!")
26+
elif user_roll < ai_roll_result:
27+
print("AI wins! Better luck next time.")
28+
else:
29+
print("It's a tie!")
30+
31+
if __name__ == "__main__":
32+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /