Correction Python
Solved
Bonjour,
I am stuck on a pix exercise. I need to correct the following code so that it works:
The only issue I have identified with my mini level is that I need to add the print command at the end.
If someone could help me it would be nice so that I can understand.
Arcadi
I am stuck on a pix exercise. I need to correct the following code so that it works:
The only issue I have identified with my mini level is that I need to add the print command at the end.
indice = "vbpewfdwaz" lettres = "}_v^yk[~jo" i = 0 tutu = '' while i < len(indice): if ord(indice[i]) < 109: tutu=tutu+chr(ord(lettres[i])+10) else: tutu=tutu+chr(ord(lettres[i])-10) i += 1 print(tutu)
If someone could help me it would be nice so that I can understand.
Arcadi
Liens connexes:
- music that goes tututu
- I'm looking for an incredible electro track.
- What is a WSD port for a printer?
- Le terme "Envoie prêt chez l'expéditeur" signifie que le colis a été préparé et est prêt à être pris en charge par le livreur chez l'expéditeur.
- display a message in python ""
- The secret word is not displaying, what can I do?
2 réponses
Hello,
Since
Then, I recommend writing your iterables in plural and your iterators in singular, e.g.
Moreover, using indices in this case is not very Pythonic. Unlike C, you can directly iterate over the characters of a string. This will also prevent you from forgetting to increment
If you need to iterate over two iterables simultaneously (which is the case here since you want to advance on
In your case, you could have written something like this:
The program can be written even more concisely using the
Good luck!
Since
iis not incremented, the
whileloop will repeat indefinitely.
Then, I recommend writing your iterables in plural and your iterators in singular, e.g.
for element in elements: ...
Moreover, using indices in this case is not very Pythonic. Unlike C, you can directly iterate over the characters of a string. This will also prevent you from forgetting to increment
i:-)
If you need to iterate over two iterables simultaneously (which is the case here since you want to advance on
indicesand
letterssimultaneously), you can use the primitives provided by
itertoolsor the built-in Python functions: in your case, the one that is suitable is
zip.
In your case, you could have written something like this:
indices = "vbpewfdwaz" letters = "}_v^yk[~jo" tutu = "" for (indice, lettre) in zip(indices, letters): if ord(indice) < 109: tutu = tutu + chr(ord(lettre) + 10) else: tutu = tutu + chr(ord(lettre) - 10)
The program can be written even more concisely using the
str.joinfunction:
indices = "vbpewfdwaz" letters = "}_v^yk[~jo" tutu = "".join( chr(ord(lettre) + 10) if ord(indice) < 109 else chr(ord(lettre) - 10) for (indice, lettre) in zip(indices, letters) )
Good luck!
Hello Mamiemando,
Thank you very much for your response. I will study everything not just to do but especially to understand. Your complete answer helps me a lot.
Regarding the ethical writing guidelines, this part is really what I was provided with.
Best regards,
Arcadi
Thank you very much for your response. I will study everything not just to do but especially to understand. Your complete answer helps me a lot.
Regarding the ethical writing guidelines, this part is really what I was provided with.
Best regards,
Arcadi
Thank you for your feedback. Regarding programming advice, you'll see over time :-) You can also check the PEP-8 standard if you want to improve.
Good luck!
Good luck!
Hello, I have exactly the same problem, so I copied the answer but it doesn't work. I also tried print "tutu", removing the "S" from "lettres", etc. but absolutely nothing works, on
repl.it when I read my programming I get python3 main.py
HELP !!
Hello Belinda,
Good luck