higher or lower? in oop book No starch press P33

PHOTO EMBED

Sat Mar 26 2022 08:46:16 GMT+0000 (Coordinated Universal Time)

Saved by @armin10020 #python

import random

print("Lower or higher game:")
value = list(range(1, 14))
suit = ["clubs", "diamonds", "heats", "slades"]
rank = ["ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "jack", "queen", "king"]
cards = []
# for role in suit:
#     for grade in rank:
#         cards.append((role, grade, value[(rank.index(grade))]))
cards=[(role,grade,value[(rank.index(grade))]) for role in suit for grade in rank]   
     
        # card.extend((role,value))     #for example value "1" is Ace, "2" is 2 and so on
        # you can reach grade with using .index() they are related together

eight_cards = random.sample(cards, 8)
temp1 = dict(zip(("suit", "rank", "value"), eight_cards[0]))
temp2 = 0
print(temp1)
user_points = 0

# for cards in eight_cards[1:]:

#     user_input = input("your turn: higher or lower???\n")
#     if cards[2] >

for cards in range(1, 8):

    user_input = input("your turn: higher or lower???\n")
    if (eight_cards[cards][2] > eight_cards[cards - 1][2] and user_input == "h") or (
        eight_cards[cards][2] < eight_cards[cards - 1][2] and user_input == "l"
    ):
        user_points += 20
    else:
        user_points-=15
        
    print(user_points)
    
    
content_copyCOPY