Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2018
1,274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. #BUGS
  2. # unable to input non-lower case guesses DONE
  3. # endless loop if 'heads' or 'tails' not entered DONE
  4.  
  5. import random
  6. import logging
  7. logging.basicConfig(level=logging.DEBUG, format=' %(asctime)s - %(levelname)s - %(message)s')
  8. logging.debug('Start of program')
  9.  
  10.  
  11. guess = ''
  12. while guess.lower() not in ('heads', 'tails'):
  13.     print('Guess the coin toss! Enter heads or tails:')
  14.     guess = input()
  15.     if guess.lower() not in ('tails', 'heads'):
  16.         raise Exception('You must guess "heads" or "tails".')
  17.     logging.debug('The user\'s guess is: ' + guess)
  18. toss = random.randint(0, 1) # 0 is tails, 1 is heads
  19. logging.debug('The toss is: ' + str(toss))
  20.  
  21. if toss == guess.lower():
  22.     print('You got it!')
  23. else:
  24.     print('Nope! Guess again!')
  25.     guesss = input()
  26.     if guess.lower() not in ('tails', 'heads'):
  27.         raise Exception('You must guess "heads" or "tails".')
  28.     logging.debug('The user\'s guess is: ' + guess)
  29.     if toss == guess.lower():
  30.        print('You got it!')
  31.     else:
  32.         print('Nope. You are really bad at this game.')
  33.  
  34. logging.debug('End of program')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement