Last active
August 29, 2015 14:07
-
-
Save restrepo/2044fe6c5733d2897097 to your computer and use it in GitHub Desktop.
Multiplicar
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/env python | |
import os.path | |
import random | |
import time | |
def multiplicar(a,b): | |
resultado=input('%sx%s = ' %(a,b)) | |
if resultado==a*b: | |
return True | |
else: | |
print('Error! el resultado correcto es: %s' %(a*b)) | |
return False | |
def tablas_aleatorias(n=10): | |
"n: numero de veces que se pregunta" | |
puntaje=0 | |
for i in range(n): | |
a=random.randrange(1,11) | |
b=random.randrange(1,11) | |
if multiplicar(a,b): | |
puntaje=puntaje+1 | |
return puntaje | |
def main(n=10): | |
"n: numero de veces que se pregunta" | |
start = time.time() | |
puntaje=tablas_aleatorias(n) | |
end = time.time() | |
record=end-start | |
print('Tu puntaje fue %s en un tiempo de %g segundos' %(puntaje,record)) | |
if os.path.isfile('record'): | |
f=open('record') | |
oldrecord=eval(f.read()) | |
f.close() | |
else: | |
oldrecord=100000 | |
if record<oldrecord and puntaje==n: | |
print('Felicitaciones! nuevo record') | |
f=open('record','w') | |
f.write('%s' %record) | |
f.close() | |
if __name__=='__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment