-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhigher-lower-card.py
More file actions
85 lines (64 loc) · 2.51 KB
/
Copy pathhigher-lower-card.py
File metadata and controls
85 lines (64 loc) · 2.51 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Higher or lower
import random
# Card deck and Suit
SUIT_TUPLE = ('Spades', 'Hearts', 'Clubs', 'Diamonds')
RANK_TUPLE = ('Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King')
NCARDS = 8
# pass in a deck and this function return a random card from the deck
def getCard(deckListIn):
thisCard = deckListIn.pop()
return thisCard
def shuffle(deckListIn):
deckListOut = deckListIn.copy()
random.shuffle(deckListOut)
return deckListOut
print("Welcome to Higher or Lower")
print("You have to choose whether the next card to be shown will be higher or lower than the current card.")
print("Getting it right adds 20 points; get it wrong and you lose 15 points.")
print("You have 50 points to start.")
print()
startingDeckList = []
for suit in SUIT_TUPLE:
for thisValue, rank in enumerate(RANK_TUPLE):
cardDict = {'rank':rank, 'suit':suit, 'value':thisValue + 1}
startingDeckList.append(cardDict)
score = 50
while True:
print()
gameDeckList = shuffle(startingDeckList)
currentCardDict = getCard(gameDeckList)
currentCardRank = currentCardDict['rank']
currentCardValue = currentCardDict['value']
currentCardSuit = currentCardDict['suit']
print("starting card is:", currentCardRank + " of " + currentCardSuit)
print()
for cardNumber in range(0, NCARDS):
answer = input("Will the next card be higher or lower than the " + currentCardRank + " of " + currentCardSuit + "? (enter h or l)")
answer = answer.casefold()
nextCardDict = getCard(gameDeckList)
nextCardRank = nextCardDict['rank']
nextCardSuit = nextCardDict['suit']
nextCardValue = nextCardDict['value']
print("Next card is:", nextCardRank + " of " + nextCardSuit)
if answer == 'h':
if nextCardValue > currentCardValue:
print("You got it right, it was higher")
score += 20
else:
print("sorry it was not higher")
score -= 15
elif answer == 'l':
if nextCardValue < currentCardValue:
print("You got it right, it was lower")
score += 20
else:
print("sorry it was not lower")
score -= 15
print("Your score is:", score)
print()
currentCardRank = nextCardRank
currentCardValue = nextCardValue
goAgain = input("To play again, press ENTER, or 'q' to quit:")
if goAgain == 'q':
break
print("BYE!")