How to create a easy game with Python

import random
num=random.randint(1,100)
play=True
while play:
x=int(input('Key in your guess:'))
if x>num:
print(f'Wrong number ! {x} is larger than the answer!')
print('Please guess again!')
elif x<num:
print(f'Wrong number ! {x} is smaller than the answer!')
print('Please guess again!')
elif x==num:
print(f'Yes! the answer is {num}')
play=False

The game is about guessing number, just paste it to your editor, then save it as *.py file.

Using the command line to execute the program

For example : I save the code as game.py, then use command line typing code below

python game.py

Guess your number !

Machine Learning | Deep Learning | https://linktr.ee/yanwei