+ 1

Can someone help with python?

I Iearn python online and came across with 2 questions - rot13 problem, and a question from codingbat site - "Given 2 strings, a and b, return the number of the positions where they contain the same length 2 substring". I have the answers but still struggle to understand. Any help will be appreciated, here or in private message, thank you!

13th Oct 2022, 10:22 PM
Liat123
Liat123 - avatar
3 Answers
+ 4
If you have the solution, then why don't you attach your code, so we have a better idea what you don't understand. Also some example of the expected inputs and outputs would be useful, because the task description is not very clear.
14th Oct 2022, 4:03 AM
Tibor Santa
Tibor Santa - avatar
+ 1
def rot_13(): encoding={} abc='abcdefghijklmnopqrstuvwxyzabcdefghijklm' ABC='ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLM' for i in range(0,26): encoding.update({abc[i] : abc[i+13]}) encoding.update({ABC[i] : ABC[i+13]}) return encoding print(rot_13()) def decode(s): key = rot_13() sentence = [] for i in range(0, len(s)): if key.get(s[i], 'none') != 'none': sentence.append(key[s[i]]) else: sentence.append(s[i]) new_sentence = ''.join(sentence) return new_sentence print(rot_13('V NZ YRNEAVAT CLGUBA JVGU FUR PBQRF NPNQRZL!'))
14th Oct 2022, 8:15 AM
Liat123
Liat123 - avatar
+ 1
It supposed to say "I Am learning python with code academy". There's full dictionary in the question but it's a photo so I can't attach Thanks!
14th Oct 2022, 8:16 AM
Liat123
Liat123 - avatar