Computer Code Python CCP n°4 : Conditions et booléens

lgsp(40)
Published in
#python
Words
159
Reading
1 min
8y
Listen to this post
~1 min

Table of Contents

  1. Les booléens
  2. Les opérateurs booléens
  3. Mélange
  4. Conditions
  5. Bilan
  6. Pour aller plus loin

Les booléens

2 == 2
'hello' == 'Hello'
2 != 2
'hello' != 'Hello'
2 < 3
'hello' < 'Hello'
2 > 3
3 > 2
2 <= 1
2 <= 3
2 >= 3
3 >= 2

Les opérateurs booléens

True and True
True and False
False and True
False and False
True or True
True or False
False or True
False or False
not True
not False

Mélange

('hello' == 'Hello') and (2 < 3)
('hello' == 'Hello') or (2 < 3)
not ('hello' == 'Hello') and (2 < 3)
not ('hello' == 'Hello') or (2 < 3)
not ( ('hello' == 'Hello') and (2 < 3) )

Conditions

age = int(input('Entrez votre age : '))
if age < 15:
    print("Vous n'avez pas la majorité sexuelle en France.")
elif age < 18:
    print("Vous n'avez pas la majorité légale en France.")
else:
    print('Vous êtes majeur en France.")

Bilan

Nous avons vu ensemble dans ce cours :

  • La comparaison entre les booléens
  • Les opérateurs booléens
  • Le mélange des deux
  • La structure conditionnelle

Pour aller plus loin

Computer Code Python CCP n°4 : Conditions et booléens | Ecency