Last active
March 23, 2020 11:39
-
-
Save kw-andy/21b57d8221838ac1462f8e55f7b7c01f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
# Question 6 creer une classe Mot avec un attribut mot et une fonction comptelettre | |
# qui prend un parametre une chaine d'une lettre et revoie le nombre d'occurences | |
#dans le mot. attenton cela ne doit pas entre sensible a la casse | |
>>> mot = Mot('Bonjour') | |
>>> mot.mot | |
'Bonjour' | |
>>> mot.comptelette('o') | |
2 | |
>>> mot.comptelettre('B') == mot.comptelettre('b') == 1 | |
True | |
''' | |
class Mot(): | |
def __init__(self,the_mot): | |
self.the_mot = the_mot | |
self.num_of_let = num_of_let | |
def mot(self): | |
print("'{}'".format(self.the_mot)) | |
def comptelettre(self,letter): | |
self.num_of_let = self.the_mot.count(self.letter) | |
return self.num_of_let | |
toto = Mot('c est un arbre a fleurs') | |
toto.mot() | |
toto.comptelettre('a') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment