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 !

Written by

Machine Learning / Deep Learning / Python / Flutter cakeresume.com/yanwei-liu

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store