Advertisement
Pandaaaa906

gamble

Jun 21st, 2019
635
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.20 KB | None | 0 0
  1. from random import randint
  2.  
  3.  
  4. def roll_dice(n=3):
  5.     return [randint(1, 6) for _ in range(n)]
  6.  
  7.  
  8. project = {'big': lambda x: 9 <= x <= 18,
  9.            'small': lambda x: 0 <= x <= 8,
  10.            'odd': lambda x: x % 2 != 0,
  11.            'even': lambda x: x % 2 == 0,
  12.            'big_odd': lambda x: 9 <= x <= 18 and x % 2 != 0,
  13.            'small_odd': lambda x: 8 >= x >= 1 and x % 2 != 0,
  14.            'big_even': lambda x: 9 <= x <= 18 and x % 2 == 0,
  15.            'small_even': lambda x: 8 >= x >= 1 and x % 2 == 0,
  16.            }
  17. choices = tuple(project.keys())
  18. QUIT_WORDS = ('quit', 'q')
  19.  
  20.  
  21. def get_int_input(prompt="", quit_words=QUIT_WORDS):
  22.     while True:
  23.         ret = input(prompt)
  24.         if ret in quit_words:
  25.             return None
  26.         if ret.isdigit():
  27.             return int(ret)
  28.  
  29.  
  30. def get_choice(choices, prompt="Input Your Choice:", quit_words=QUIT_WORDS):
  31.     for i, k in enumerate(choices, 1):
  32.         print(i, k)
  33.     while True:
  34.         ret = input(prompt)
  35.         if ret in quit_words:
  36.             return None
  37.         if ret.isdigit() and len(choices) >= int(ret):
  38.             return choices[int(ret) - 1]
  39.  
  40.  
  41. def game_start():
  42.     your_money = get_int_input('recharge money:')
  43.     if your_money is None:
  44.         your_money = 0
  45.  
  46.     while your_money > 0:
  47.         buy = get_choice(choices)
  48.         bet_money = get_int_input('bet amount:')
  49.         if bet_money is None:
  50.             break
  51.         if bet_money > your_money:
  52.             print('bet error')
  53.             continue
  54.         result = roll_dice()
  55.         results = sum(result)
  56.         print('___GAME RESULT')
  57.         print(f"You're betting {buy}")
  58.         if project[buy](results):
  59.             print('Lottery result {}, you win'.format(result))
  60.             your_money += bet_money
  61.             print('This amount of bet in this council {}, balance {}'.format(bet_money, your_money))
  62.         else:
  63.             print('Lottery result {},you lose'.format(result))
  64.             your_money -= bet_money
  65.             print('This amount of bet in this council {}, balance {}'.format(bet_money, your_money))
  66.         input("Press Enter to Continue")
  67.  
  68.     print('GAME OVER')
  69.  
  70.  
  71. if __name__ == '__main__':
  72.     game_start()
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement