Kodewick
Commencer à apprendre →
Mini-défi←→0 / 70

Âge requis pour le film

#017Mini-défi&& (age >= 13 || p)6 min

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.

Exemples
CanWatch(8, "G", false)→True
CanWatch(10, "PG-13", true)→True
CanWatch(16, "18", true)→False
La fonctionfunc CanWatch(age int, rating string, withParent bool) bool
main.go
package 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
}
Ctrl + Entrée lance aussi le code
Résultat

Exécuter teste les exemples. Quand ils sont bons, appuie sur Envoyer.