Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Input a number. Random choice odd or even and compare with the input. If user choose correct, he win. If not, try again.
- import random
- def odd_or_even():
- n = int(input('Your guest: \n'))
- random_choice = random.choice([(0, 'even'), (1, 'odd')])
- print('We choose {}'.format(random_choice[1]))
- if n % 2 == random_choice[0]:
- print('You win')
- return
- else:
- print('Try again\n------')
- odd_or_even()
- Sample run:
- Your guest:
- 2
- We choose odd
- Try again
- ------
- Your guest:
- 3
- We choose odd
- You win
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement