#๐ Homework problem
74 messages ยท Page 1 of 1 (latest)
@humble sphinx
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.
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?
basically what the error says is that you are trying to add a string (combination of letters) with a int (numbers), which does not work well
yeah it's just a series of characters
could also include numbers
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
do I have to do that in this scenerio?
yes, + isn't defined for a string and an int
in distance put
distance = int(input("enter your distance value: "))
it's in there alredy
this error now is that you didnt define the cipher variable
I wonder why they didn't do so in the book
you need to give the variable a value before you can use it
you mean cipher?
uh just a sec an you paste your code im having difficulty reading it lmao
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)
cipher > ord('z'): what is cipher here? what's it's value?
I don't know
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)
I just noticed that
this should work i think you meant cipherValue
have you assigned a value to cipher anywhere in the code?
can you share your reference code?
im pretty sure this works i tested it you might want to check this out
that code doesn't use a variable named cipher
i replaced cipher with cipherValue and put the part in the loop
@humble sphinx issue solved?
isnt his correct?
if the cipher gives a letter higher than z it goes back to a
so why don't you break it down into steps
for a given letter, how do you find it's cipher letter?
ok, what next?
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
yep. now that we've got there, you have the example code, how does it not fulfill the prompt just as it is?
well I don't know
it didn't work with the inputs that the grading thing inputted
therefore it is incorrect
can you see the inputs the failing test case is giving?
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.