#๐Ÿ”’ Homework problem

74 messages ยท Page 1 of 1 (latest)

humble sphinx
#

I'm reading about caesar cypher's in class and I'm using the code from the example as reference. How do I create a script that fits the function in the instructions? I'm really struggling a lot understanding coding and it's pretty frustrating because I don't have the creativity to write anything up

remote turretBOT
#

@humble sphinx

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

deep prairie
#

first step seems like it would be creating the file the instructions specify

Oops, misread it,s orry

#

that error message you get, pick it apart a bit for me

#

do you know what a string is?

coarse arrow
humble sphinx
#

could also include numbers

deep prairie
#

it could, but numbers in strings are just characters

#

python doesn't differentiate between the character '7' and the character 'b' when it comes to string operations.

#

you can convert a string to an int though, by passing the string to the int() function

humble sphinx
#

do I have to do that in this scenerio?

deep prairie
#

yes, + isn't defined for a string and an int

coarse arrow
#

in distance put

distance = int(input("enter your distance value: "))
humble sphinx
#

it's in there alredy

coarse arrow
humble sphinx
#

yeah I forgot to post the updated ss

coarse arrow
humble sphinx
#

I wonder why they didn't do so in the book

coarse arrow
humble sphinx
#

yeah I know

#

would it be set to a string?

coarse arrow
humble sphinx
#

yeah

#

what would I set the cipher value to

coarse arrow
#

uh just a sec an you paste your code im having difficulty reading it lmao

humble sphinx
#

yeah I gotchu

#

User inputs their plaintext
plainText = input("Enter your message: ")
distance = int(input("Enter your distance value: "))
code = ""
for ch in plainText:
ordvalue = ord(ch)
cipherValue = ordvalue + distance
if cipher > ord('z'):
cipherValue = ord('a') + distance -
(ord('z') - ordvalue + 1)
code += chr(cipherValue)
print(code)

deep prairie
#

cipher > ord('z'): what is cipher here? what's it's value?

humble sphinx
#

I don't know

coarse arrow
#

im not exactly sure what cipher is supposed to do just give me a sec...

#

also btw the code += chr(cipherValue) is outside of the loop

#
plainText = input("Enter your message: ")
distance = int(input("Enter your distance value: "))
code = ""
for ch in plainText:
    ordvalue = ord(ch)
    cipherValue = ordvalue + distance
    if cipherValue > ord('z'):
        cipherValue = ord('a') + distance - \
                      (ord('z') - ordvalue + 1)
    code += chr(cipherValue)
print(code)
humble sphinx
#

I just noticed that

coarse arrow
deep prairie
humble sphinx
#

no

#

the code I used for reference doesn't do so

deep prairie
#

can you share your reference code?

coarse arrow
humble sphinx
#

the code on the top right

deep prairie
#

that code doesn't use a variable named cipher

coarse arrow
#

i replaced cipher with cipherValue and put the part in the loop

#

@humble sphinx issue solved?

humble sphinx
coarse arrow
#

if the cipher gives a letter higher than z it goes back to a

humble sphinx
#

I don't know

#

but it sure didn't output such

deep prairie
#

so why don't you break it down into steps

#

for a given letter, how do you find it's cipher letter?

humble sphinx
#

It's corresponding to a ascii value

#

I think

deep prairie
#

so lets say step one: convert the letter to it's ascii value with ord()

#

next step

humble sphinx
#

set the ciphervalue

#

with ord + distance

#

using the plaintext and distance

deep prairie
#

ok, what next?

humble sphinx
#

then add calculations to the ciphervalue to bridge the gap

#

between the character a and z

#

then you add the code to the cipher value

deep prairie
#

yep. now that we've got there, you have the example code, how does it not fulfill the prompt just as it is?

humble sphinx
#

well I don't know

#

it didn't work with the inputs that the grading thing inputted

#

therefore it is incorrect

deep prairie
#

can you see the inputs the failing test case is giving?

humble sphinx
#

yeah it doesn't say what text they used but the distance value is off

remote turretBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.