Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. #Imports the random module
  2. import random
  3.  
  4. #Initializes lists and other variables
  5. cardNumber = ['A','2','3','4','5','6','7','8','9','10','J','Q','K']
  6. suite = ['Spades','Clubs','Hearts','Diamonds']
  7. deck = []
  8. cardValue = 0
  9. guess = ''
  10.  
  11. #Actually creates the deck
  12. for i in range (13):
  13. for j in range (4):
  14. deck.append(cardNumber[i]+' of '+suite[j])
  15.  
  16. #Setting up the rules of the game
  17.  
  18.  
  19. #Gives a value to the card so it can be compared to others.
  20. def value(x):
  21. global cardValue
  22. cardvalue = 0
  23. print(x)
  24. if deck[0][0] == 'A':
  25. cardValue = 1
  26. elif deck[0][0] == '2':
  27. cardValue = 2
  28. elif deck[0][0] == '3':
  29. cardValue = 3
  30. elif deck[0][0] == '4':
  31. cardValue = 4
  32. elif deck[0][0] == '5':
  33. cardValue = 5
  34. elif deck[0][0] == '6':
  35. cardValue = 6
  36. elif deck[0][0] == '7':
  37. cardValue = 7
  38. elif deck[0][0] == '8':
  39. cardValue = 8
  40. elif deck[0][0] == '9':
  41. cardValue = 9
  42. elif deck[0][:2] == '10':
  43. cardValue = 10
  44. elif deck[0][0] == 'J':
  45. cardValue = 11
  46. elif deck[0][0] == 'Q':
  47. cardValue = 12
  48. elif deck[0][0] == 'K':
  49. cardValue = 13
  50.  
  51. #Actual game function
  52. def game():
  53. try:
  54. lives = int(input('How many lives would you like? '))
  55. except:
  56. lives = int(input('How many lives would you like? '))
  57. points = 0
  58. while lives > 0:
  59. draw = 0 #Initializes draw
  60. random.shuffle(deck) #Shuffles the deck everytime so deck won't run out
  61. print(deck[draw]) #Prints the first card from the deck
  62. value(deck[draw]) #Assigns a value to the first card using the value func
  63. value1 = cardValue
  64. print(value1)
  65. draw += 1 #Goes to the next card in deck to avoid duplicates
  66. guess = input('Do you think the next card is higher, lower or the same? ')
  67. guess = guess.lower()
  68. print(deck[draw]) #Prints second card from the deck
  69. value(deck[draw]) #Assigns a value to the first card using the value func
  70. value2 = cardValue
  71. print(value2) #THIS IS WHERE THE ISSUE IS
  72.  
  73. #Awards points for correct guesses
  74. if guess == 'higher' and value2 > value1:
  75. points += 1
  76. print('\nYou got a point! \nNext Round\n')
  77. elif guess == 'same' and value2 == value1:
  78. points += 1
  79. print('\nYou got a point! \nNext Round\n')
  80. elif guess == 'lower' and value2 < value1:
  81. points += 1
  82. print('\nYou got a point! \nNext Round\n')
  83. elif guess == 'quit':
  84. break
  85. else:
  86. print('Try again! \n Next Round\n')
  87. lives += -1
  88. print('Game Over!\nYou recieved',points,'point(s)')
  89.  
  90. game() #Actually runs the game
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement