Jan-12-2018, 03:01 PM
Hi I'm a teacher and I just began learning Python so I can show some tips to my students. I code a little math game and I have an issue with global vs local variable.
I'm trying to define 2 games and launch the first one and the second on a condition (bonne == 3), but I don't know how to do this.
(I'm a french speaking teacher, so sorry for my poor english)
Thank you
I'm trying to define 2 games and launch the first one and the second on a condition (bonne == 3), but I don't know how to do this.
(I'm a french speaking teacher, so sorry for my poor english)
Thank you
import random import time print ('Bienvenue') def GAME() : bonne = 0 mauvaise = 0 jeu = 0 while True : a= int(random.randint (0,10)) b = int(random.randint (0,10)) reponse = a+b print (str(a) + '+' + str(b) + '=' + '?') joueur = input ('Quelle est la bonne réponse ?') time.sleep (0.5) if int(joueur) == reponse : print ('Bravo') bonne = bonne + 1 time.sleep(0.3) print ('Tu as ' + str(bonne) + ' bonnes réponses et ' + str(mauvaise) + ' mauvaises réponses') else : print ('VRAIMENT !!!') mauvaise = mauvaise + 1 time.sleep(0.3) print ('Tu as ' + str(bonne) + ' bonnes réponses et ' + str(mauvaise) + ' mauvaises réponses') if bonne == 3 : print ('Tu as complété le jeu avec ' + str(mauvaise) + ' mauvaise réponse') jeu = jeu + 1 break if mauvaise == 3 : print ('Trop de mauvaises réponses') time.sleep (0.5) print ('GAME OVER') break def GAME2(): << def of GAME 2 if jeu == 0 : << play the fisrt game GAME() if jeu == 1 : << play the second game if you succeed the first one GAME2()