Voici le code:Pourquoi mon poste César ne fonctionne-t-il pas correctement?
text = input("What's your text: ")
shift = int(input("What's your shift: "))
def caesar_shift(text, shift):
cipher = ""
for i in text:
if i.isalpha():
stayIn = ord(i) + shift
if stayIn > ord('z'):
stayIn -= 26
lastLetter = chr(stayIn)
cipher += lastLetter
print("Your ciphertext is: ", cipher)
return cipher
caesar_shift(text, shift)
Quand je le lance, et par exemple, le test est bonjour monde, et le changement est 1, je reçois:
What's your text: hello world
What's your shift: 1
Your ciphertext is: i
Your ciphertext is: if
Your ciphertext is: ifm
Your ciphertext is: ifmm
Your ciphertext is: ifmmp
Your ciphertext is: ifmmpp
Your ciphertext is: ifmmppx
Your ciphertext is: ifmmppxp
Your ciphertext is: ifmmppxps
Your ciphertext is: ifmmppxpsm
Your ciphertext is: ifmmppxpsme
Pourquoi? Est-ce que je fais quelque chose de mal, merci d'avance!
Pas de réponse est juste, je me demande pourquoi il l'imprime comme ça, comment puis-je obtenir la dernière réponse? – Samir
@Samir: Non, la réponse est incorrecte, que vous remarquerez si vous la décalez. J'ai mis à jour l'explication pour couvrir votre autre question aussi. –