Last active
December 19, 2015 22:39
-
-
Save ychaouche/6028905 to your computer and use it in GitHub Desktop.
lottery.py, a game of lottery proposed on reddit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "Versin 2 ? " | |
| import random | |
| def welcome_msg(): | |
| print 'Welcome to the Python lottery! Here are the rules' | |
| print 'Specify the amount of numbers you want in the lottery...' | |
| print 'Place your bet!' | |
| print 'For each number guessed correctly, regardless of position' | |
| print 'you win %50 of your bet...' | |
| print 'Guess all numbers correct and win 500% of your bet' | |
| print 'Get no numbers right and lose all of your money!' | |
| def ready_to_play(): | |
| return raw_input('Are you ready to play? ').lower() in ('y','yes','yea') | |
| def choose_length(): | |
| return int(raw_input('How many numbers would you like in this lottery? ')) | |
| def choose_bet(): | |
| return int(raw_input('In dollars, how much are you willing to bet? ')) | |
| def choose_numbers(length): | |
| print "Enter one number at a time" | |
| return [int(raw_input(">")) for x in xrange(length)] | |
| def generate_numbers(length): | |
| return [random.randint(1,100) for x in xrange(length)] | |
| def calculate_money(numbers_list,random_numbers,bet): | |
| numbers_list.sort() | |
| random_numbers.sort() | |
| if numbers_list == random_numbers : | |
| print "YOU WON THE JACKPOT ! all numbers were correct" | |
| return 5 * bet | |
| money = 0 | |
| for number in numbers_list : | |
| if number in random_numbers : | |
| print "%d is in the list" % number | |
| money += bet / 2.0 | |
| return money | |
| def play(): | |
| length = choose_length() | |
| bet = choose_bet() | |
| numbers_list = choose_numbers(length) | |
| random_numbers = generate_numbers(length) | |
| money = calculate_money(numbers_list,random_numbers,bet) | |
| print 'The winning numbers are',random_numbers | |
| print 'Your numbers were',numbers_list | |
| print "you have won %d dollars !" % money | |
| def main(): | |
| welcome_msg() | |
| if ready_to_play(): | |
| play() | |
| else: | |
| print('Guess today just isn\'t your lucky day! ') | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment