1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| # -*- coding: utf-8 -*-
import os
from random import randrange
import traceback # Standard interface to extract, format and print stack traces of Python programs
import time
import sys
def choix(tx,a,b):
""" si renvoie 'r0' la saisie est alpha
si 'r1' la saisie est conforme
si 'r2' la saisie demande la sortie
si 'r3' la saisie est numérique mais hors les bornes"""
w='r0' ; message="! Numérique seulement et entre "\
+str(a)+ " et "+str( b)
x = input(tx)
try:
x=int(x)
w='r1' # print("OK")
if not(a <= x <= b):
w='r3'
message=" -> -> le choix doit être entre "\
+str(a)+" et "+str(b)
return w,x
else:
message=''
return w,x
except Exception:
exc_type, exc_value, exc_traceback = sys.exc_info()
print("Function error in line {:d}: {}".format(exc_traceback.tb_lineno, exc_value.args[0]))
time.sleep(5)
# except Exception as e:
# print("Erreur: ",e) # inutile ici mais pour voir
# if x=='':
# message=("......Vous avez demandé la sortie !")
# w='r2'
# return w,0
# else:
# return w,0
#finally:
# print(message+'\n')
#----
try:
msg1=' compris [Return Quit]: '
i=1 ; ii=1 ; c1=0 ; c2=10 ;m1=1 ; m2=20
while i:
while ii:
z=choix('Votre choix entre '+str(c1)+'..'+str(c2)+msg1,c1,c2)
if z[0]=='r2':
print(" Donc c'est fini ! !.")
ii=0 ; i=0
elif z[0]=='r1':
y=1 #;print('pas fini')
while y:
w=choix('Quelle mise entre '+str(m1)+'..'+str(m2)+msg1,m1,m2)
if w[0]=='r1':
y=0 ; i=0
tirage=randrange(c2+1)
#print('la mise',z,w,'\n')
print('tirage ',tirage,'\n')
print("Vous avez misé",w[1],". sur le N°"\
,z[1], "et c'est le",tirage,"qui est sorti.\n")
if z[1]==tirage:
print(' *** vous avez gagné ! !\n'.upper())
else:
print("....Vous avez perdu....\n")
elif w[0]=='r2':
print('..Fini, fini..')
y=0; ii=0; i=0
else:
print('re..miser ? ',end='')
except Exception:
exc_type, exc_value, exc_traceback = sys.exc_info()
print("Function error in line {:d}: {}".format(exc_traceback.tb_lineno, exc_value.args[0]))
time.sleep(5)
time.sleep(5) |
Partager