Skip to content

Instantly share code, notes, and snippets.

@kw-andy
Last active March 23, 2020 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kw-andy/21b57d8221838ac1462f8e55f7b7c01f to your computer and use it in GitHub Desktop.
Save kw-andy/21b57d8221838ac1462f8e55f7b7c01f to your computer and use it in GitHub Desktop.
'''
# 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