parc.py

Created by schraf

Created on September 15, 2018

457 Bytes

Un parc d’attraction est accessible aux enfants de 13 ans et plus. Il est également accessible aux enfants de moins de 13 ans s’ils sont accompagnés par un adulte. Écrire une fonction parc qui admet 2 paramètres, l’âge du visiteur et s’il est accompagné ou non d’un adulte (False ou True). En sortie on obtient :

>> parc(15,False)
"Bienvenue"
>> parc(17,True)
"Bienvenue"
>> parc(7,True)
"Bienvenue"
>> parc(9,False)
"Interdit"


def parc(age,adulte):
  if age<13 and not(adulte):
    return "Interdit"
  return "Bienvenue"
  
# Version 2 laborieuse
def parc2(age,adulte):
  if age>=13: return "Bienvenue"
  elif age<13 and adulte: return "Bienvenue"
  else: return "Interdit"
  
# Version 3
def parc3(age,adulte):
  return "Interdit" if age<13 and not(adulte) else "Bienvenue"
  
  # Version 4
def parc4(age,adulte):
  return ["Bienvenue","Interdit"][age<13 and not(adulte)]

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.