Skip to content

Instantly share code, notes, and snippets.

@amineds
Created December 4, 2021 21:18
Show Gist options
  • Save amineds/5a7efcf189c4de1b88d983b2cc03465b to your computer and use it in GitHub Desktop.
Save amineds/5a7efcf189c4de1b88d983b2cc03465b to your computer and use it in GitHub Desktop.
import sys
import random
from termcolor import colored, cprint
sequence = 15 #number of operations to solve
positive = 0 #good results
for i in range(0,sequence):
x= random.randint(2,9); y= random.randint(2,9)
print('\n')
print(f'==> {x} x {y} = ')
for line in sys.stdin:
try:
if int(line.rstrip()) == x*y :
print(colored('GOOD RESULT, WELL DONE !','green'))
positive=positive + 1
else :
print(colored(f'SORRY, BAD RESULT ! {x} * {y} = {x*y} !','red'))
break
except ValueError:
print('PLEASE INTER A VALID INTEGER')
print("\n")
print("YOU'RE DONE !")
print("\n")
cprint(f"YOU SCORED {positive} / {sequence}",'magenta',attrs=['bold'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment