Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- def roll_dice(n=3):
- return [randint(1, 6) for _ in range(n)]
- project = {'big': lambda x: 9 <= x <= 18,
- 'small': lambda x: 0 <= x <= 8,
- 'odd': lambda x: x % 2 != 0,
- 'even': lambda x: x % 2 == 0,
- 'big_odd': lambda x: 9 <= x <= 18 and x % 2 != 0,
- 'small_odd': lambda x: 8 >= x >= 1 and x % 2 != 0,
- 'big_even': lambda x: 9 <= x <= 18 and x % 2 == 0,
- 'small_even': lambda x: 8 >= x >= 1 and x % 2 == 0,
- }
- choices = tuple(project.keys())
- QUIT_WORDS = ('quit', 'q')
- def get_int_input(prompt="", quit_words=QUIT_WORDS):
- while True:
- ret = input(prompt)
- if ret in quit_words:
- return None
- if ret.isdigit():
- return int(ret)
- def get_choice(choices, prompt="Input Your Choice:", quit_words=QUIT_WORDS):
- for i, k in enumerate(choices, 1):
- print(i, k)
- while True:
- ret = input(prompt)
- if ret in quit_words:
- return None
- if ret.isdigit() and len(choices) >= int(ret):
- return choices[int(ret) - 1]
- def game_start():
- your_money = get_int_input('recharge money:')
- if your_money is None:
- your_money = 0
- while your_money > 0:
- buy = get_choice(choices)
- bet_money = get_int_input('bet amount:')
- if bet_money is None:
- break
- if bet_money > your_money:
- print('bet error')
- continue
- result = roll_dice()
- results = sum(result)
- print('___GAME RESULT')
- print(f"You're betting {buy}")
- if project[buy](results):
- print('Lottery result {}, you win'.format(result))
- your_money += bet_money
- print('This amount of bet in this council {}, balance {}'.format(bet_money, your_money))
- else:
- print('Lottery result {},you lose'.format(result))
- your_money -= bet_money
- print('This amount of bet in this council {}, balance {}'.format(bet_money, your_money))
- input("Press Enter to Continue")
- print('GAME OVER')
- if __name__ == '__main__':
- game_start()
Advertisement
Advertisement