Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need some help with this computer science question! I was able to submit a running program but got some errors! Help Please? Question: Errors:

I need some help with this computer science question! I was able to submit a running program but got some errors! Help Please?

Question:

image text in transcribed

Errors: image text in transcribed

my code currently:

def encode(plaintext,n): ans = "" for i in range(len(plaintext)): ch = plaintext[i] if ch==" ": ans+=" " elif (ch.isupper()): ans += chr((ord(ch) + n-65) % 26 + 65) else: ans += chr((ord(ch) + n-97) % 26 + 97) return ans print(encode("the quick brown fox.", 4))

Exercise 6.4 Street Addre Exercise 6.5 Shift Cipher Exercise 6.5 Shift Cipher One of the simplest forms of encryption is the Caesar Cipher, also known as a shift cipher. In this technique, each letter in the plaintext is replaced by a letter a fixed distance away in the alphabet, wrapping around at the end (or beginning) as necessary. ihift cipher example For example, if you encoded 'dog' by shifting two to the right, 'd' would be replaced by ' f ', 'o' would be replaced by ' q ', and ' g ' would be replaced by 'i', so the final encoded text would be 'fqi'. 'zoo' would be encoded as 'bqq', because the 'z' would wrap around to the beginning of the alphabet again. Create program called shift_cipher.py containing the function encode. The function should take as parameters the text to encode (in all lower case), and the number of letters to shift (guaranteed to be between -26 and 26). It should return the encoded text, and leave spaces and punctuation as-is, without changing them. Hint: You will need to use ord() and chr() to convert letters to numbers and back again in order to shift them. You should also use the modulo operator (\%), although you do not have to. >> print(encode("the quick brown fox.", 4)) x xli uymgo fvsar jsb. Test Failedi Babaission does not pass pep\} oheoks Satoviderisubaigeiomithift eipher.py:16t16t E225 aiesimin whiteg9ace around operator positive shift {0.0/3.0} - epere qv be kacaen wa peuiv adavar. 7 + cene qv bea kuczan ba peulv adxvbak 2 negative shift [0,0,3.0) - gl rylybe bgb iszjf tifl y qryrode njerpese-brko bongeor gi rylyte hgh ikxjr ifyl y qryrede mejcyapeyhakn hanpeel shift by 26(0.0v2.0) Test Zailedi 'this ezouldn't change" 1 - 'thie shouldmat change' - tieis ahsuldn't ehecgu 7 + taia ahouldnot ehaege 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions