-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp22.py
More file actions
48 lines (37 loc) · 1.36 KB
/
p22.py
File metadata and controls
48 lines (37 loc) · 1.36 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
# p22.py
# Rishi Saravanan
# Python 3.11.9
# Description:
'''
Write a Dice Game program that generates two random dice values between 1 and 6 for you, and 2 for the computer.
You get to roll as many times as you like (if you don't like your 2 dice), while the computer only rolls once, after you
have decided that you like your two dice.
Determine who wins, you or the computer.
'''
from random import randint
while True:
player1 = randint(1,6)
player2 = randint(1,6)
playerTotal = player1 + player2
change = input("You have %i and %i which equals to %i. Do you want to change these numbers (y/n)" %(player1,player2,playerTotal))
if change == 'n':
break
print()
computer1 = randint(1,6)
computer2 = randint(1,6)
computerTotal = computer1 + computer2
print("Computer values were:", computer1, "and",computer2, "which equals", computerTotal)
print()
if playerTotal > computerTotal:
print("Players wins")
elif playerTotal < computerTotal:
print("Computer wins")
else:
print("It's a tie")
'''
===================== RESTART: C:\Users\rishi\python\p22.py ====================
You have 1 and 5 which equals to 6. Do you want to change these numbers (y/n)y
You have 4 and 3 which equals to 7. Do you want to change these numbers (y/n)n
Computer values were: 4 and 2 which equals 6
Players wins
'''