card slot machine

import random


dict = {'A':4,'KING':4,'QUEEN':4, 'J':4, '10':4, '9':4, '8':4,'7':4,'6':4,'5':4,'4':4,'3':4,'2':4}


ROWS = 3

COLS = 3

NUM_TIMES = 5

MAX_BET = 500 




def sequence_game(alhp):

    all_cards = []

    for i, dict in alhp.items():

        for _ in range(dict):

            all_cards.append(i)

    return all_cards        



def deposit():

  while True:

    amount_input = input("how much amount you want to deposit? $ ")

    amount = 0

    if amount_input.isdigit():

      amount = int(amount_input)

      if amount > 0:

        break

      else:

        print("amount must be greater than 0")

  return amount






def get_bet_amount():

    while True:


     bet_amount_input = (input("how much amount you want to bet ? $ "))

     bet_amount = 0




     if bet_amount_input.isdigit():

      bet_amount = int(bet_amount_input)

     if bet_amount > 0:

        print("okay lets start")

     else:

       print("bet amount must be 0")

     if 1<= bet_amount <= MAX_BET:

        return bet_amount 


     else:

        print(f"bet amount must be in between 1-{MAX_BET}")



def random_choice_result(cols,all_cards):




     random_choice = []




     for col in range(cols):

      value = random.choice(all_cards)

      all_cards.remove(value)


      random_choice.append(value)

     return random_choice


def print_random_choice_result(random_choice,bet_amount):






     lets_distribute_all_cards = input(" ready to distribute ? ")

     if lets_distribute_all_cards == 'y':



        print(random_choice)

        return(random_choice)

     elif lets_distribute_all_cards == 'q':

       exit()




def winning_check_result(random_choice,bet_amount):  

  score = 0

  if random_choice[0]==random_choice[1]==random_choice[2]:

      score = bet_amount * 10

      print(f"congratulations you won {score}$")

  elif (random_choice[0]==random_choice[1]!=random_choice[2] or 

         random_choice[0]!=random_choice[1]==random_choice[2]) or (random_choice[0] == 

random_choice[2] != random_choice[1]):

      score = bet_amount * 2

      print(f"your score is 2,you won {score}$")



  elif set(random_choice) =={'A', 'KING','QUEEN'}:

      score = bet_amount * 9

      print(f"congratulations!,you got a high run, your score is 9, you won {score}$")

  elif set(random_choice) == {'A','2','3'}:

      score = bet_amount * 8

      print(f"congratulations!,you got a 2nd high run, your score is 6, you have won {score}$" )

  elif set(random_choice) == {'KING','QUEEN','J'}:

      score = bet_amount * 7

      print(f"congratulations,you got 3rd high run, your score is 7, you have won {score}$")

  elif set(random_choice) == {'QUEEN','J','10'}:

      score = bet_amount * 6

      print (f"congratulations,you got 4th high run, your score is 6, you have won {score}$")

  elif set(random_choice) == {'J','10','9'}:

     score = bet_amount * 5

     print(f"congracts,you got 5th high run, your score is 3 you have won {score}$")

  elif set(random_choice) == {'10','9','8'}:

     score = bet_amount * 4

     print(f"congratulations,you got 6th high run, your score is 2 you have won {score}$")

  elif set(random_choice) == {'9','8','7'}:

     score = bet_amount * 3

     print(f"congratulations,you got 7th high run,your score is 3, you have won {score}$")

    

      




















  else:

      print(f"sorry! you have lost {bet_amount}$ , lets try again")

  return score






def game(deposit_balance):

  

 while True:

  





      

   bet_amount = get_bet_amount()

   

   if bet_amount > deposit_balance:

     print("sorry!,you have no money left,deposit again")

   

    

     

    

   


   current_amount = deposit_balance-bet_amount


   sequence = sequence_game(dict)

   result = print(f"you are betting {bet_amount},{sequence},your rest amount is{current_amount}!alert you might loss this amount")

   results =random_choice_result(COLS,sequence) 

   print_results = print_random_choice_result(results,bet_amount)


   winnings_score = winning_check_result(print_results,bet_amount)

   return winnings_score - bet_amount

  


   



def main():

  deposit_balance = deposit()

  while True:

    

      

   choice = input("do you want to keep playing or not ")

   if choice !='y':

     quit()

   

                                           

   deposit_balance+=game(deposit_balance)

   print(f"your current balance is {deposit_balance}")

    

  

  

   

main()      





































       

Comments

Popular posts from this blog

Programming

Card Game In Python