Hi
I dont' understandard why the tirage() def doesnt execute (it works only after else block)
Could you help please??
import random
def tirage():
for i in range(6):
print(random.randint(1, 40))
print("Voulez-vous jouer au loto", "?")
reponse= input("Entrez votre réponse:")
print("Ma réponse est: " + reponse)
if reponse == 'oui':
print("Super,le tirage va commencer" '!')
tirage()
else:
print ("Tant pis, bonne soirée...")
It looks like there is something wrong
with the indentation, it is inconsistent.
Especially lines 11-12 compared to 4-5
When fixed everything works fine.
Paul
(Apr-30-2021, 06:59 AM)DPaul Wrote: [ -> ]It looks like there is something wrong
with the indentation, it is inconsistent.
Especially lines 11-12 compared to 4-5
When fixed everything works fine.
Paul
sure but what is the better whay to check identation without use REPL
which code editor I have to use for good identation?
The simplest editor will do.
Even IDLE will tell you that something in the syntax is not right.
You can also count TABs , can't go wrong.
But nothing will verify the logic of the indentation,
that is entirely up to you.
Paul
(Apr-30-2021, 08:02 AM)DPaul Wrote: [ -> ]The simplest editor will do.
Even IDLE will tell you that something in the syntax is not right.
You can also count TABs , can't go wrong.
But nothing will verify the logic of the indentation,
that is entirely up to you.
Paul
I try to use tab in many different way but impossible to do my code working!!!
now indentation is good
import random
def tirage():
for i in range(6):
print(random.randint(1, 40))
print("Voulez-vous jouer au loto", "?")
reponse= input("Entrez votre réponse:")
print("Ma réponse est: " + reponse)
if reponse == 'Oui' or reponse == 'oui':
print("Super,le tirage va commencer" '!')
else:
print ("Tant pis, bonne soirée...")
tirage()
input('press enter to continue')
but if I put the tirage() function in the if block instead the else block, I have the message SyntaxError: invalid syntax
how use this function in the if block?
And I also noted that if I delete the else block and put the function in the if block it works
import random
def tirage():
for i in range(6):
print(random.randint(1, 40))
return i
print("Voulez-vous jouer au loto", "?")
reponse= input("Entrez votre réponse:")
print("Ma réponse est: " + reponse)
if reponse == 'Oui' or reponse == 'oui':
print("Super,le tirage va commencer" '!')
tirage()
Hi Jip,
I see no problem in calling the function from the if block. I think your indentation is still not correct. All the lines from the "if" block must have the same indentation (preferably 4 spaces).
import random
def tirage():
for i in range(6):
print(random.randint(1, 40))
print("Voulez-vous jouer au loto", "?")
reponse = input("Entrez votre réponse:")
print("Ma réponse est: " + reponse)
if reponse == 'Oui' or reponse == 'oui':
print("Super,le tirage va commencer" '!')
tirage()
else:
print("Tant pis, bonne soirée...")
input('press enter to continue')
Output:
Voulez-vous jouer au loto ?
Entrez votre réponse:oui
Ma réponse est: oui
Super,le tirage va commencer!
27
7
1
33
25
13
press enter to continue
(Apr-30-2021, 10:50 AM)ibreeden Wrote: [ -> ]Hi Jip,
I see no problem in calling the function from the if block. I think your indentation is still not correct. All the lines from the "if" block must have the same indentation (preferably 4 spaces).
import random
def tirage():
for i in range(6):
print(random.randint(1, 40))
print("Voulez-vous jouer au loto", "?")
reponse = input("Entrez votre réponse:")
print("Ma réponse est: " + reponse)
if reponse == 'Oui' or reponse == 'oui':
print("Super,le tirage va commencer" '!')
tirage()
else:
print("Tant pis, bonne soirée...")
input('press enter to continue')
Output:
Voulez-vous jouer au loto ?
Entrez votre réponse:oui
Ma réponse est: oui
Super,le tirage va commencer!
27
7
1
33
25
13
press enter to continue
hi ibredeen
you are right
there was just an empty line before else in my code....