+ 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!
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.
+ 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!'))
+ 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!