Advertisement
rdhammack

Coin Flipper Program in Python

Feb 5th, 2017
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.28 KB | None | 0 0
  1. #Coin Flipper Program
  2. #
  3. #Dustin Hammack
  4. #Feb. 4, 2017
  5.  
  6. import random
  7.  
  8. print('\t\t\tLets see how lucky you are. ')
  9. print('\t\t\tHere you will choose either heads or tails, ')
  10. print('\t\t\tand see if you can win the flip. Best out of ')
  11. print('\t\t\t100 wins. \n\n\n')
  12.  
  13. def flippedCoin():
  14.         userChoice = input('\nPlease choose heads or tails: ')
  15.         print()
  16.         choice = userChoice.lower()
  17.         heads = random.randrange(1,100)
  18.         tails = 100 - heads
  19.         if (choice == 'heads'):
  20.                 if (heads > tails):
  21.                         print('You won with ' + str(heads) + ' flips.')
  22.                         print('And tails lost with only ' + str(tails) + ' flips.')
  23.                 elif (tails > heads):
  24.                         print('You lost with only ' + str(heads) + ' flips.')
  25.                         print('And tails won with ' + str(tails) + ' flips.')
  26.                         print('\n\nTry your luck again?')
  27.                 elif (heads == tails):
  28.                         print('It was a tie!')
  29.                 playingAgain()
  30.         elif (choice == 'tails'):
  31.                 if (heads < tails):
  32.                         print('You won with ' + str(tails) + ' flips.')
  33.                         print('And heads lost with only ' + str(heads) + ' flips.')
  34.                 elif (tails < heads):
  35.                         print('You lost with only ' + str(tails) + ' flips.')
  36.                         print('And heads won with ' + str(heads) + ' flips.')
  37.                         print('\n\nTry your luck again?')
  38.                 elif (heads == tails):
  39.                         print('It was a tie!')
  40.                 playingAgain()
  41.         else:
  42.                 print('\nPlease enter only "heads" or "tails"')
  43.                 flippedCoin()
  44.                 playingAgain()
  45.  
  46. def playingAgain():                
  47.         playAgain = input('\n\nWould you like to play again? ')
  48.         again = playAgain.lower()
  49.         if (again == 'yes'):
  50.                 flippedCoin()
  51.         elif (again == 'no'):
  52.                 print('\n\nThanks for playing. See you next time!')
  53.         elif (again != 'yes' and again != 'no'):
  54.                 print('Please enter Yes or No ')
  55.                 playingAgain()
  56.                
  57.                        
  58. flippedCoin()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement