Last active
October 3, 2018 18:20
-
-
Save jorisbertomeu/b2ab20dc804f5e65867b308b5b9da400 to your computer and use it in GitHub Desktop.
Entrainement à l'exercice https://www.youtube.com/watch?v=cTp4M9IDjgQ de Fabien Olicard - MacOS Only
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
""" | |
Name: Notion de congruence _ Entrainement mental - (c.f https://www.youtube.com/watch?v=cTp4M9IDjgQ) | |
Author: Joris Bertomeu <joris.bertomeu@gmail.com> | |
Date: 10-02-18 | |
Usage: : python ./congruence.py | |
""" | |
import random | |
from os import system | |
import time | |
import sys | |
D_SAY = 'say -v Thomas ' | |
D_INTERVAL = 1.5 | |
D_SERIE_LENGTH = 5 | |
def representsInt(s): | |
try: | |
int(s) | |
return True | |
except ValueError: | |
return False | |
def printUsage(binaryName): | |
print 'Usage: {0} <Longueur de la série> <Interval entre chiffres en secondes>'.format(binaryName) | |
def say(toSay): | |
system('{0}"{1}"'.format(D_SAY, toSay)) | |
if __name__ == '__main__': | |
serie = [] | |
askNumber = -1 | |
for idx, arg in enumerate(sys.argv): | |
if idx == 1 and representsInt(arg): | |
D_SERIE_LENGTH = int(arg) | |
elif idx == 2 and representsInt(arg): | |
D_INTERVAL = int(arg) | |
elif idx > 0: | |
printUsage(sys.argv[0]) | |
sys.exit(-1) | |
say('Série avec {0} chiffres'.format(D_SERIE_LENGTH)) | |
for x in range(D_SERIE_LENGTH): | |
serie.append(random.randint(0,9)) | |
say(serie[-1]) | |
time.sleep(D_INTERVAL); | |
idxToRemove = random.randint(0,D_SERIE_LENGTH - 1) | |
say('Série avec le chiffre retiré') | |
for x in range(D_SERIE_LENGTH): | |
if x == idxToRemove: | |
continue | |
say(serie[x]) | |
time.sleep(D_INTERVAL); | |
typed = input("Quel est le chiffre retiré ? ") | |
if typed == serie[idxToRemove]: | |
print 'Bravo 🎉! Le chiffre retiré était {0}'.format(serie[idxToRemove]) | |
say('Bravo ! Le chiffre retiré était effectivement {0}'.format(serie[idxToRemove])) | |
else: | |
print 'Désolé 😢! Le chiffre retiré n\'était pas {0} mais était {1}'.format(typed, serie[idxToRemove]) | |
say('Malheureusement, ce n\'était pas {0} ! Le chiffre retiré était le {1}'.format(typed, serie[idxToRemove])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment