Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # BlackJack
- from random import randint
- # Introduction and options.
- print('Welcome to BlackJack')
- print('Please choose an option: \'Help\' or \'Play\'')
- response = input()
- # Main game function.
- def Play():
- first_num = randint(1, 11)
- secon_num = randint(1, 10)
- player_total = first_num + secon_num
- dealer_num1 = randint(2, 11)
- dealer_num2 = randint(2, 10)
- dealer_total = dealer_num1 + dealer_num2
- print('Dealer\'s first number is:', dealer_num1)
- print('\nYour first number is:', first_num)
- print('Your second number is:', secon_num)
- print('Total:', player_total)
- print('Would you like a new number?: \'Yes/No\'')
- new_number = input()
- if (new_number == 'Yes' or new_number == 'yes'):
- third_num = randint(1, 11)
- player_total = third_num + player_total
- print('Your new number is', third_num)
- print('New total:', player_total)
- print('\nDealer\'s second number is:', dealer_num2)
- print('Dealer\'s total:', dealer_total)
- if ((player_total > dealer_total and player_total <= 21)
- or dealer_total > 21 or player_total == 21):
- print('\nYou win!')
- if (player_total < dealer_total or player_total > 21):
- print('\nYou lose!')
- # Help function, in case the game is unclear.
- def Help():
- print('The objective of the game is to achieve')
- print('the number 21 or a higher number than')
- print('the dealer. If your number is higher than')
- print('21 then you are bust and you lose, however')
- print('if the dealers number is above 21 and yours')
- print('is below then you win.')
- # Function that loops the game so you can replay.
- def Play2():
- Play()
- start = True
- while (start):
- again = input('\nPlay again?: \'Yes/No\' ')
- if (again == 'Yes' or again == 'yes'):
- print()
- Play()
- if (again == 'No' or again == 'no'):
- start = False
- # When options are typed, the according if statement calls a function.
- if (response == 'Play' or response == 'play'):
- Play2()
- if (response == 'Help' or response == 'help'):
- Help()
- # Allows the users to play after viewing the help option.
- print('\nWould you like to Play now?')
- play_now = input()
- if (play_now == 'Yes' or play_now == 'yes'):
- Play2()
Add Comment
Please, Sign In to add comment