Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def guessing_game():
- print("""
- welcome to the guessing game
- this is the rules:
- think on a number between 1 - 100
- after every guess wright
- yes - if this is your number
- bigger - if your number is bigger
- smaller - if your number is smaller
- exit - for exit the game
- """)
- number = random.randint(40, 60)
- bigger_than = 1
- smaller_than = 100
- game_dict = {
- 'big': "bigger",
- 'no big': "bigger",
- 'bigger': 'bigger',
- 'no bigger': 'bigger',
- 'not small': 'bigger',
- 'not smaller': 'bigger',
- 'small': 'smaller',
- 'no small': 'smaller',
- 'smaller': 'smaller',
- 'no smaller': 'smaller',
- "not big": 'smaller',
- "not bigger": 'smaller'
- }
- while True:
- if bigger_than == smaller_than:
- print(f'you are a liar!')
- break
- ans = input(f'your number is {number}? ').lower()
- action = game_dict.get(ans)
- if action == 'smaller':
- smaller_than = number - 1
- number = random.randint(bigger_than, smaller_than)
- elif action == 'bigger':
- bigger_than = number + 1
- number = random.randint(bigger_than, smaller_than)
- elif 'no' in ans:
- print('wright if bigger or smaller')
- elif 'yes' in ans:
- print('I win!')
- break
- elif 'exit' in ans:
- print('bye bye')
- break
- else:
- print('wrong value')
- guessing_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement