def single_letter_guess(guess, word):
"""
Usage: allow us to guess the word one by one
Input: guess, word
Links: called by process_guess()
"""
global guessed_letters
global lives_remaining
if word.find(guess) == -1:
# letter guess was incorrect
lives_remaining = lives_remaining - 1
guessed_letters = guessed_letters + guess.lower() # Cela est FAUX
if all_letters_guessed(word):
return True # Cela semble resonnable
return False # Cela est totalement FAUX
L'indentation est essentielle
def single_letter_guess(guess, word):
"""
Usage: allow us to guess the word one by one
Input: guess, word
Links: called by process_guess()
"""
global guessed_letters
global lives_remaining
if word.find(guess) == -1:
# letter guess was incorrect
lives_remaining = lives_remaining - 1
guessed_letters = guessed_letters + guess.lower()
if all_letters_guessed(word):
return True
return False
Indentation correcte
In [40]:
sA='toto'
print(sA == 'toto')
In [41]:
sA='toto'
Bolean= (sA == 'toto' and sA != 'toto')
print(Bolean)
In [43]:
True and not True
Out[43]:
In [43]:
s="les amis de mes amis sont mes amis"
prop_1 = 'les ennemis'
prop_2 = 'de mes ennemis'
conclusion = 'sont mes amis'
if (prop_1 in s):
prop_a1 = "+"
else:
prop_a1 = "-"
if (prop_2 in s):
prop_a2 = "+"
else:
prop_a2 = "-"
if (conclusion in s):
conclusion_a = "+"
else:
conclusion_a = "-"
print("| " + prop_a1 + " | " + prop_a2 + " | alors | " + conclusion_a +" |" ,end="")
e1 | e2 | ---> | r |
---|---|---|---|
+ | + | alors | + |
In [47]:
sPetit = "rois"
sMoyen = "hummains"
sGrand = "mortels"
premise_majeure = "Tous les "+sMoyen+" sont "+sGrand
premise_mineure = "Tous les "+sPetit+" sont "+sMoyen
conclusion = "Tous "+sPetit+" sont "+sGrand
print("Sylogisme : ")
print(premise_majeure)
print('Or, ',end="")
print(premise_mineure)
print('Donc, ',end="")
print(conclusion)
Rappel des précéances sur les operateurs arithmetiques
Operateur | Exemple de calcul | Resultat |
---|---|---|
Parethèses | $(1+2)*3$ | 9 |
Exponentielle | $1*2**2$ | 5 |
multiplication/division | $10/2+1$ | 6 |
addition/soustraction | $10+3-1$ | 12 |
Toujours de gauche à droite
Précéance des operateurs de comparaison
Operateurs | Exemple de calcul | Résultat |
---|---|---|
+,-,... | not 1 - 1 | 1 |
== | not 1 or 0 == 0 | 1 |
Précéance des operateurs logiques pour des expression boléenes
Operateurs | Exemple de calcul | Résultat |
---|---|---|
or | False and False or True | True |
and | True and False == False | True |
not x | not True or False == False | True |
In [42]:
not True or False == False
Out[42]:
In [32]:
True and False == False
Out[32]:
In [12]:
True == False or True
Out[12]:
In [19]:
not 1 - 1
Out[19]:
In [40]:
False and False or True
Out[40]:
In [9]:
x = 4
y = 2
if not 1 + 1 == y or 7 == 8 and x == 4:
#if x == 4 or 7 == 8 and not 1 + 1 == y:
# les operateurs logiques se lisent de gauch à droite
print("Yes")
elif x > y:
print("No")
In [1]:
sA = range(1,15)
for i in range(0,len(sA)):
#the Blueberry is hidden in the box whose numner equals 11
if i > 3 and i < 8 : #Boxes 4, 5, 6, 7 contain potatores
print(sA[i],end=" Bananas ")
elif i < len(sA):
print(sA[i],end=" Apples ") # This condition prevails by order to the following
elif i == 1:
print(sA[i],end=" Blueberry ") # This code will never used
else:
print(sA[i],end=" Raspberry ")# This code will never used
print(", Is it the right package ? : {}".format( i == 11-1)) # Prints false exept for 11
La commande qui suit if est executée si et seulement si la condition True est valable une seulle et unique fois, par conscéquent et elle ne sera jamais executée si elle est False, ou si l'on à executé une boucle sur une variable qui a parcouru toute une liste