+ 1
ERROR: not all arguments converted during string formatting
What is wrong with this code? The function Encrypt takes a String and performs the following operations on it that will produce a cyphertext. 1. Take the ASCII of the Character 2. If the ASCII Character is an odd number you add 4 to the value 3. If it is even you subtract 4 from the ASCII Value 4. Convert the ASCII back to characters and return that String as the Ciphertext Decrypt does the opposite. Given a cyphertext it returns the original String. https://code.sololearn.com/c4etsGO66r9M/?ref=app
5 ответов
+ 5
I don't know much Python, but the error was in the logic, you can't subtract a number from a character. So I made little changes in your code and it worked fine, but you didn't provide sample inputs and outputs so I assumed my output is right. I have mentioned the changes in the code as comments(#here)
https://code.sololearn.com/cP01Gn7xc5Fh/?ref=app
PS:Inside the if statements, I have used the ASCII values of the characters for comparison, and nothing else. Your code worked then =)
PPS:I want 50 upvotes plz🥺
+ 3
Triz I have updated the code in my answer, check it again, I think it now produces the output right. I created an empty string and appended each encrypted/decrypted character one by one in it and then returned it
+ 2
Rishi I updated the code; I provided sample inputs n outputs
+ 2
Rishi Thank you very much!
+ 2
Triz happy to help =)