Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Imports the random module
- import random
- #Initializes lists and other variables
- cardNumber = ['A','2','3','4','5','6','7','8','9','10','J','Q','K']
- suite = ['Spades','Clubs','Hearts','Diamonds']
- deck = []
- cardValue = 0
- guess = ''
- #Actually creates the deck
- for i in range (13):
- for j in range (4):
- deck.append(cardNumber[i]+' of '+suite[j])
- #Setting up the rules of the game
- #Gives a value to the card so it can be compared to others.
- def value(x):
- global cardValue
- cardvalue = 0
- print(x)
- if deck[0][0] == 'A':
- cardValue = 1
- elif deck[0][0] == '2':
- cardValue = 2
- elif deck[0][0] == '3':
- cardValue = 3
- elif deck[0][0] == '4':
- cardValue = 4
- elif deck[0][0] == '5':
- cardValue = 5
- elif deck[0][0] == '6':
- cardValue = 6
- elif deck[0][0] == '7':
- cardValue = 7
- elif deck[0][0] == '8':
- cardValue = 8
- elif deck[0][0] == '9':
- cardValue = 9
- elif deck[0][:2] == '10':
- cardValue = 10
- elif deck[0][0] == 'J':
- cardValue = 11
- elif deck[0][0] == 'Q':
- cardValue = 12
- elif deck[0][0] == 'K':
- cardValue = 13
- #Actual game function
- def game():
- try:
- lives = int(input('How many lives would you like? '))
- except:
- lives = int(input('How many lives would you like? '))
- points = 0
- while lives > 0:
- draw = 0 #Initializes draw
- random.shuffle(deck) #Shuffles the deck everytime so deck won't run out
- print(deck[draw]) #Prints the first card from the deck
- value(deck[draw]) #Assigns a value to the first card using the value func
- value1 = cardValue
- print(value1)
- draw += 1 #Goes to the next card in deck to avoid duplicates
- guess = input('Do you think the next card is higher, lower or the same? ')
- guess = guess.lower()
- print(deck[draw]) #Prints second card from the deck
- value(deck[draw]) #Assigns a value to the first card using the value func
- value2 = cardValue
- print(value2) #THIS IS WHERE THE ISSUE IS
- #Awards points for correct guesses
- if guess == 'higher' and value2 > value1:
- points += 1
- print('\nYou got a point! \nNext Round\n')
- elif guess == 'same' and value2 == value1:
- points += 1
- print('\nYou got a point! \nNext Round\n')
- elif guess == 'lower' and value2 < value1:
- points += 1
- print('\nYou got a point! \nNext Round\n')
- elif guess == 'quit':
- break
- else:
- print('Try again! \n Next Round\n')
- lives += -1
- print('Game Over!\nYou recieved',points,'point(s)')
- game() #Actually runs the game
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement