Le cinéma vérifie le classement : "G" est pour tout le monde ; "PG-13" demande 13 ans ou plus, ou un parent présent (withParent) ; "18" demande 18 ans ou plus, avec ou sans parent. Écris CanWatch(age, rating, withParent) pour renvoyer true si la personne peut voir le film. Le classement est toujours l’un de ces trois.
CanWatch(8, "G", false)→TrueCanWatch(10, "PG-13", true)→TrueCanWatch(16, "18", true)→Falsefunc CanWatch(age int, rating string, withParent bool) boolpackage main
func CanWatch(age int, rating string, withParent bool) bool {
if rating == "G" {
return true
}
// ton code ici: un if pour "PG-13" et un pour "18"; renvoie true si c'est permis
return false
}
Exécuter teste les exemples. Quand ils sont bons, appuie sur Envoyer.