Guest User

Untitled

a guest
Jan 2nd, 2018
1,164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 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 guess.lower() == 'tails':
  22.     guess = 0
  23. if toss == guess:
  24.     print('You got it!')
  25. else:
  26.     print('Nope! Guess again!')
  27.     guess = input()
  28.     if guess.lower() not in ('tails', 'heads'):
  29.         raise Exception('You must guess "heads" or "tails".')
  30.     logging.debug('The user\'s guess is: ' + guess)
  31.     if guess.lower() == 'heads':
  32.         guess = 1
  33.     if toss == guess:
  34.        print('You got it!')
  35.     else:
  36.         print('Nope. You are really bad at this game.')
  37.  
  38. logging.debug('End of program')
Advertisement
Add Comment
Please, Sign In to add comment