nouveau fichier : 2/0LoopOnWord.py

nouveau fichier : 2/1LoopOnWord.py
	nouveau fichier : 2/2Rot13.py
	nouveau fichier : 2/3Rot13.py
	nouveau fichier : 2/4Rot13.py
	modifié :         2Prog.md
This commit is contained in:
2022-10-14 00:28:49 +02:00
parent 84d386a4ae
commit 0214c87c6c
6 changed files with 348 additions and 0 deletions

8
python/2/0LoopOnWord.py Executable file
View File

@@ -0,0 +1,8 @@
#! /usr/bin/python3
# -*- coding: utf-8 -*-
voyelles="aeiouy"
for element in voyelles:
print(element," ", end=' ')
print("\n")

8
python/2/1LoopOnWord.py Normal file
View File

@@ -0,0 +1,8 @@
#! /usr/bin/python3
# -*- coding: utf-8 -*-
voyelles="aeiouy"
for element in voyelles:
print(ord(element)," ", end=' ')
print("\n")

11
python/2/2Rot13.py Normal file
View File

@@ -0,0 +1,11 @@
#! /usr/bin/python3
# -*- coding: utf-8 -*-
message="secretfrperg"
for element in message:
n=ord(element)-97
m=(n+13)%26
rot=chr(m+97)
print(rot,end='')
print("\n")

23
python/2/3Rot13.py Normal file
View File

@@ -0,0 +1,23 @@
#! /usr/bin/python3
# -*- coding: utf-8 -*-
def carot13(lettre):
"""retourne la lettre correspondante en rot13, on suppose que lettre est entre a et z"""
n=ord(lettre)-97
m=(n+13)%26
rot=chr(m+97)
return rot
def marot13(mot):
"""retourne le mot correspondant en rot13, on suppose que le mot est composé de lettres entre a et z"""
out="";
for lettre in mot:
out+=carot13(lettre)
return out
# test
print("test rot13")
print("abcdefghijklmnopqrstuvwxyz")
print(marot13("abcdefghijklmnopqrstuvwxyz"))
print(marot13(marot13("abcdefghijklmnopqrstuvwxyz")))

37
python/2/4Rot13.py Normal file
View File

@@ -0,0 +1,37 @@
#! /usr/bin/python3
# -*- coding: utf-8 -*-
def carot13(lettre):
"""retourne la lettre correspondante en rot13, on suppose que lettre est entre a et z"""
n=ord(lettre)-97
m=(n+13)%26
rot=chr(m+97)
return rot
def marot13(mot):
"""retourne le mot correspondant en rot13, on suppose que le mot est composé de lettres entre a et z"""
out="";
for lettre in mot:
out+=carot13(lettre)
return out
# test
print("rot13")
print("abcdefghijklmnopqrstuvwxyz")
print(marot13("abcdefghijklmnopqrstuvwxyz"))
print(marot13(marot13("abcdefghijklmnopqrstuvwxyz")))
def rot13(phrase):
"""retourne la phrase correspondant en rot13, on suppose que la phrase est composée de mots séparés par un espace et composé de lettres entre a et z"""
maListeDeMots=phrase.split()
listeDeMotsEnRot13=[marot13(mot) for mot in maListeDeMots]
phraseEnRot13=" ".join(listeDeMotsEnRot13)
return phraseEnRot13
message="the lazy dog jumped over the quick brown fox"
print()
print("test")
print(message)
print(rot13(message))
print(rot13(rot13(message)))