Gallery

Learn by remixing real projects.

Open any example in the Playground and tweak it live. No setup, no signup.

Source preview

Side-by-side: Baobab ↔ Python

Every example translates between Baobab and Python. Click any card above to open it in the Playground.

Baobab · calculator.bao
BAO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# calculator.bao — calculatrice simple fonction calculer(a, op, b): si op == "+": retourner a + b sinonsi op == "-": retourner a - b sinonsi op == "*": retourner a * b sinonsi op == "/": si b == 0: afficher("Erreur: division par zero") retourner nul retourner a / b sinon: afficher("Opération inconnue: " + op) retourner nul fonction principale(): afficher("=== Calculatrice Baobab ===") afficher("4 + 5 = " + texte(calculer(4, "+", 5))) afficher("10 - 3 = " + texte(calculer(10, "-", 3))) afficher("6 * 7 = " + texte(calculer(6, "*", 7))) afficher("20 / 4 = " + texte(calculer(20, "/", 4))) calculer(1, "%", 2) retourner 0 principale()
Python · calculator.py
PY
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# calculator.py — simple calculator def calculer(a, op, b): if op == "+": return a + b elif op == "-": return a - b elif op == "*": return a * b elif op == "/": if b == 0: print("Erreur: division par zero") return None return a / b else: print("Opération inconnue: " + op) return None def principale(): print("=== Calculatrice Baobab ===") print("4 + 5 = " + str(calculer(4, "+", 5))) print("10 - 3 = " + str(calculer(10, "-", 3))) print("6 * 7 = " + str(calculer(6, "*", 7))) print("20 / 4 = " + str(calculer(20, "/", 4))) calculer(1, "%", 2) return 0 principale()
Baobab · todo.bao
BAO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# todo.bao — gestionnaire de tâches taches = [] fonction ajouter(titre): taches.ajouter({ "titre": titre, "fait": faux }) fonction terminer(index): taches[index]["fait"] = vrai afficher("Tâche " + texte(index + 1) + " terminée.") fonction afficher_liste(): afficher("📋 Mes tâches:") pour i dans intervalle(longueur(taches)): t = taches[i] marque = "[x]" si t["fait"] sinon "[ ]" afficher(marque + " " + texte(i + 1) + ". " + t["titre"]) ajouter("Apprendre Baobab") ajouter("Construire une app") ajouter("Partager avec la communauté") afficher_liste() terminer(0) afficher_liste()
Python · todo.py
PY
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# todo.py — task manager taches = [] def ajouter(titre): taches.append({ "titre": titre, "fait": False }) def terminer(index): taches[index]["fait"] = True print("Tâche " + str(index + 1) + " terminée.") def afficher_liste(): print("📋 Mes tâches:") for i in range(len(taches)): t = taches[i] marque = "[x]" if t["fait"] else "[ ]" print(marque + " " + str(i + 1) + ". " + t["titre"]) ajouter("Apprendre Baobab") ajouter("Construire une app") ajouter("Partager avec la communauté") afficher_liste() terminer(0) afficher_liste()

School Management

Open in Playground
Baobab · school.bao
BAO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# school.bao — gestion des étudiants classe Etudiant: fonction nouveau(nom, notes): ce.nom = nom ce.notes = notes fonction moyenne(): total = 0 pour n dans ce.notes: total = total + n retourner total / longueur(ce.notes) etudiants = [ nouveau Etudiant("Amina", [16, 14, 16.5]), nouveau Etudiant("Kofi", [10, 13, 13]), nouveau Etudiant("Fatou", [18, 17, 16.5]), ] afficher("🎓 École Baobab") meilleur = etudiants[0] pour e dans etudiants: afficher(e.nom + " — moyenne: " + texte(e.moyenne())) si e.moyenne() > meilleur.moyenne(): meilleur = e afficher("Meilleur: " + meilleur.nom)
Python · school.py
PY
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# school.py — student management class Etudiant: def __init__(self, nom, notes): self.nom = nom self.notes = notes def moyenne(self): total = 0 for n in self.notes: total = total + n return total / len(self.notes) etudiants = [ Etudiant("Amina", [16, 14, 16.5]), Etudiant("Kofi", [10, 13, 13]), Etudiant("Fatou", [18, 17, 16.5]), ] print("🎓 École Baobab") meilleur = etudiants[0] for e in etudiants: print(e.nom + " — moyenne: " + str(e.moyenne())) if e.moyenne() > meilleur.moyenne(): meilleur = e print("Meilleur: " + meilleur.nom)
Baobab · bank.bao
BAO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# bank.bao — système bancaire classe Compte: fonction nouveau(titulaire, solde): ce.titulaire = titulaire ce.solde = solde fonction deposer(montant): si montant <= 0: afficher("Montant invalide") retourner faux ce.solde = ce.solde + montant afficher("Dépôt: +" + texte(montant) + " → " + texte(ce.solde)) retourner vrai fonction retirer(montant): si montant > ce.solde: afficher("Solde insuffisant") retourner faux ce.solde = ce.solde - montant afficher("Retrait: -" + texte(montant) + " → " + texte(ce.solde)) retourner vrai fonction transferer(autre, montant): si ce.retirer(montant): autre.deposer(montant) afficher("Transfert " + ce.titulaire + " → " + autre.titulaire + ": " + texte(montant)) afficher("🏦 Banque Baobab") amina = nouveau Compte("Amina", 500) kofi = nouveau Compte("Kofi", 0) afficher("Compte Amina: " + texte(amina.solde)) amina.deposer(250) amina.retirer(100) amina.transferer(kofi, 200) afficher("Compte Amina: " + texte(amina.solde)) afficher("Compte Kofi: " + texte(kofi.solde))
Python · bank.py
PY
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# bank.py — banking system class Compte: def __init__(self, titulaire, solde): self.titulaire = titulaire self.solde = solde def deposer(self, montant): if montant <= 0: print("Montant invalide") return False self.solde = self.solde + montant print("Dépôt: +" + str(montant) + " → " + str(self.solde)) return True def retirer(self, montant): if montant > self.solde: print("Solde insuffisant") return False self.solde = self.solde - montant print("Retrait: -" + str(montant) + " → " + str(self.solde)) return True def transferer(self, autre, montant): if self.retirer(montant): autre.deposer(montant) print("Transfert " + self.titulaire + " → " + autre.titulaire + ": " + str(montant)) print("🏦 Banque Baobab") amina = Compte("Amina", 500) kofi = Compte("Kofi", 0) print("Compte Amina: " + str(amina.solde)) amina.deposer(250) amina.retirer(100) amina.transferer(kofi, 200) print("Compte Amina: " + str(amina.solde)) print("Compte Kofi: " + str(kofi.solde))
Baobab · weather.bao
BAO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# weather.bao — tableau météo jours = ["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi"] temperatures = [28, 26, 24, 27, 30] icones = ["☀️", "⛅", "🌧️", "☀️", "☀️"] afficher("🌤️ Météo de la semaine") total = 0 pour i dans intervalle(longueur(jours)): afficher(jours[i] + ": " + texte(temperatures[i]) + "°C " + icones[i]) total = total + temperatures[i] moyenne = total / longueur(jours) afficher("Moyenne: " + texte(moyenne) + "°C")
Python · weather.py
PY
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# weather.py — weather dashboard jours = ["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi"] temperatures = [28, 26, 24, 27, 30] icones = ["☀️", "⛅", "🌧️", "☀️", "☀️"] print("🌤️ Météo de la semaine") total = 0 for i in range(len(jours)): print(jours[i] + ": " + str(temperatures[i]) + "°C " + icones[i]) total = total + temperatures[i] moyenne = total / len(jours) print("Moyenne: " + str(moyenne) + "°C")

Chat Application

Open in Playground
Baobab · chat.bao
BAO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# chat.bao — application de messagerie classe Message: fonction nouveau(auteur, contenu, heure): ce.auteur = auteur ce.contenu = contenu ce.heure = heure classe Salon: fonction nouveau(nom): ce.nom = nom ce.messages = [] ce.utilisateurs = [] fonction rejoindre(utilisateur): ce.utilisateurs.ajouter(utilisateur) fonction envoyer(auteur, contenu, heure): ce.messages.ajouter(nouveau Message(auteur, contenu, heure)) fonction afficher_tout(): afficher("💬 Salon: #" + ce.nom) pour m dans ce.messages: afficher("[" + m.heure + "] " + m.auteur + ": " + m.contenu) afficher(texte(longueur(ce.utilisateurs)) + " utilisateurs · " + texte(longueur(ce.messages)) + " messages") general = nouveau Salon("général") general.rejoindre("Amina") general.rejoindre("Kofi") general.rejoindre("Fatou") general.envoyer("Amina", "Salut tout le monde!", "09:01") general.envoyer("Kofi", "Bonjour Amina 👋", "09:02") general.envoyer("Fatou", "On code en Baobab aujourd'hui?", "09:03") general.envoyer("Amina", "Oui, hâte de commencer!", "09:04") general.afficher_tout()
Python · chat.py
PY
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# chat.py — chat application class Message: def __init__(self, auteur, contenu, heure): self.auteur = auteur self.contenu = contenu self.heure = heure class Salon: def __init__(self, nom): self.nom = nom self.messages = [] self.utilisateurs = [] def rejoindre(self, utilisateur): self.utilisateurs.append(utilisateur) def envoyer(self, auteur, contenu, heure): self.messages.append(Message(auteur, contenu, heure)) def afficher_tout(self): print("💬 Salon: #" + self.nom) for m in self.messages: print("[" + m.heure + "] " + m.auteur + ": " + m.contenu) print(str(len(self.utilisateurs)) + " utilisateurs · " + str(len(self.messages)) + " messages") general = Salon("général") general.rejoindre("Amina") general.rejoindre("Kofi") general.rejoindre("Fatou") general.envoyer("Amina", "Salut tout le monde!", "09:01") general.envoyer("Kofi", "Bonjour Amina 👋", "09:02") general.envoyer("Fatou", "On code en Baobab aujourd'hui?", "09:03") general.envoyer("Amina", "Oui, hâte de commencer!", "09:04") general.afficher_tout()

Library (multi-file)

Open in Playground
Baobab · livre.bao
BAO
1
2
3
4
5
6
7
8
9
10
11
12
13
# livre.bao — un livre et son état d'emprunt classe Livre: fonction nouveau(titre, auteur): ce.titre = titre ce.auteur = auteur ce.disponible = vrai fonction emprunter(): si non ce.disponible: retourner faux ce.disponible = faux retourner vrai
Python · livre.py
PY
1
2
3
4
5
6
7
8
9
10
11
12
13
# livre.py — un livre et son état d'emprunt class Livre: def __init__(self, titre, auteur): self.titre = titre self.auteur = auteur self.disponible = True def emprunter(self): if not self.disponible: return False self.disponible = False return True
Baobab · bibliotheque.bao
BAO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# bibliotheque.bao — une collection de livres importer livre depuis "./livre.bao" classe Bibliotheque: fonction nouveau(nom): ce.nom = nom ce.livres = [] fonction ajouter(titre, auteur): ce.livres.ajouter(livre.Livre(titre, auteur)) fonction emprunter(titre): pour l dans ce.livres: si l.titre == titre: si l.emprunter(): retourner "Emprunt de " + titre retourner titre + " est deja emprunte" retourner titre + " introuvable"
Python · bibliotheque.py
PY
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# bibliotheque.py — une collection de livres import livre class Bibliotheque: def __init__(self, nom): self.nom = nom self.livres = [] def ajouter(self, titre, auteur): self.livres.append(livre.Livre(titre, auteur)) def emprunter(self, titre): for l in self.livres: if l.titre == titre: if l.emprunter(): return "Emprunt de " + titre return titre + " est deja emprunte" return titre + " introuvable"
Baobab · main.bao
BAO
1
2
3
4
5
6
7
8
9
10
11
# main.bao — point d'entrée du programme importer bibliotheque depuis "./bibliotheque.bao" biblio = bibliotheque.Bibliotheque("Centrale") biblio.ajouter("Le Petit Prince", "Saint-Exupery") biblio.ajouter("1984", "Orwell") afficher(biblio.emprunter("1984")) afficher(biblio.emprunter("1984")) afficher(biblio.emprunter("Inconnu"))
Python · main.py
PY
1
2
3
4
5
6
7
8
9
10
11
# main.py — point d'entrée du programme import bibliotheque biblio = bibliotheque.Bibliotheque("Centrale") biblio.ajouter("Le Petit Prince", "Saint-Exupery") biblio.ajouter("1984", "Orwell") print(biblio.emprunter("1984")) print(biblio.emprunter("1984")) print(biblio.emprunter("Inconnu"))