Question 1
ord('A'), ord('D'), ord('0'), ord('3')
def ieme_lettre(i):
return chr(ord('A') + i - 1)
ieme_lettre(1), ieme_lettre(5)
def donne_moi_le_code_ascii():
c = input('quel est le caractère dont vous voulez le code ascii? ')
print('le code ascii de', c, 'est', ord(c))
Question 2
def position_dans_alphabet(c):
return ord(c)-ord('A') + 1
position_dans_alphabet('M')
Question 3
for i in range(32,45) :
print(chr(i), end='')
Question 4
def est_chiffre(car):
return ord('0') <= ord(car) <= ord('9')
est_chiffre('3'), est_chiffre('a')
Question 5
def masque_numero(s):
acc = ''
for c in s :
if est_chiffre(c) :
acc = acc + '*'
else :
acc = acc + c
return acc
masque_numero('abcd 1209 sjsalk 10-2 ')