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:
37
python/2/4Rot13.py
Normal file
37
python/2/4Rot13.py
Normal 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)))
|
Reference in New Issue
Block a user