-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary.py
More file actions
45 lines (40 loc) · 1.48 KB
/
Copy pathlibrary.py
File metadata and controls
45 lines (40 loc) · 1.48 KB
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
38
39
40
41
42
43
44
45
# This function count the number of each characters in a string
def countChar():
prompt = 'Phrase à compter : '
my_text = None
my_characters = {};
while not isinstance(my_text, str):
try:
my_text = str(input(prompt))
except:
print('\nVous n\'avez pas rentré une chaîne de charactères.')
prompt = 'Entrez le numéro que vous voulez multiplier'
else:
for i in my_text:
if i in my_characters.keys():
my_characters[i] += 1
else:
if i != ' ' and i != ',' and i != '\'':
my_characters[i] = 1
result = 'Le caractère "{0}" apparaît {1} fois.'
for char, occur in my_characters.items():
print(result.format(char, occur))
# This function return the multiplication table
# between 0 and 10 from a given number
def multiplication():
prompt = 'Table de multiplication voulue : '
x = None
while not isinstance(x, int):
try:
x = int(input(prompt))
except:
print('\nVous n\'avez pas rentré un entier')
prompt = 'Entrez le numéro que vous voulez multiplier'
else:
print('\nVoici la table de {0}'.format(x))
for i in range(0, 11):
print('{0} * {1} = {2}'.format(x, i, x*i))
print('\nEt voila !')
# Test list
x = [element for element in range(20) if element % 2 == 0]
print(x)