Advertisement
DrAungWinHtut

card_game1.py

Aug 20th, 2024
273
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.11 KB | None | 1 0
  1. import random
  2. import os
  3.  
  4. exit = False
  5. money = input('How much ? : ')
  6. coin = int(money)
  7.  
  8. while not exit:
  9.     os.system('cls')
  10.     print('Choose Suit')
  11.     print('1-Spade')
  12.     print('2-Heart')
  13.     print('3-Diamond')
  14.     print('4-Club')
  15.     user_suit = input('Choose one (1,2,3,4): ')
  16.     user_number = input('Choose a Number for the Card: ')
  17.     bet = input('How much will you bet on it? ')
  18.     bet = int(bet)
  19.  
  20.     while bet > coin:
  21.         print('You dont have enough money!')
  22.         print('1-Add more money')
  23.         print('2-Lower you bet')
  24.         print('3-Exit')
  25.         bet_ans = input('Choose 1,2,3: ')
  26.         bet_ans = int(bet_ans)
  27.         if bet_ans == 1:
  28.             money = input('How much ? : ')
  29.             money = int(money)
  30.             coin = coin + money # coin += money
  31.         elif bet_ans == 2:
  32.             bet = input(f'How much will you bet on it? it must less than or equal to {coin} ')
  33.             bet = int(bet)
  34.         elif bet_ans == 3:
  35.             print('Bye!')
  36.             exit(0)
  37.  
  38.  
  39.  
  40.     user_suit = int(user_suit)
  41.     user_number = int(user_number)
  42.  
  43.  
  44.     card_number = random.randint(1,13)
  45.     card_suit = random.randint(1,4)
  46.  
  47.     if user_suit == 1:
  48.         user_suit = 'Spade'
  49.     elif user_suit == 2:
  50.         user_suit = 'Heart'
  51.     elif user_suit == 3:
  52.         user_suit ='Diamond'
  53.     elif user_suit == 4:
  54.         user_suit = 'Club'
  55.  
  56.     print(f'You choose {user_suit} of {user_number}')
  57.     os.system('pause')
  58.  
  59.  
  60.     if card_suit == 1:
  61.         card_suit = 'Spade'
  62.     elif card_suit == 2:
  63.         card_suit = 'Heart'
  64.     elif card_suit == 3:
  65.         card_suit ='Diamond'
  66.     elif card_suit == 4:
  67.         card_suit = 'Club'
  68.  
  69.     print(f'Actual Card is {card_suit} of {card_number}')
  70.  
  71.     if (user_suit==card_suit) and (user_number==card_number):
  72.         print("You won the prize!")
  73.         coin += bet * 50   #coin = coin + (bet * 50)
  74.     else:
  75.         print('You lose!')
  76.         coin -= bet     # coin = con - bet
  77.    
  78.     print(f'Now your coin is {coin}')
  79.  
  80.     ans = input('Continue?...(y/n): ')
  81.     if(ans != 'y'):
  82.         exit = True
  83.    
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement