Tell us what’s happening:
I was told to create a function named caesar and put all my existing code within the function body. I tried this but my code still wont pass I honestly don’t know what to do
Your code so far
):
):
# User Editable Region
def caesar():
alphabet = 'abcdefghijklmnopqrstuvwxyz'
shift = 5
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
translation_table = str.maketrans(alphabet, shifted_alphabet)
text = 'hello world'
encrypted_text = text.translate(translation_table)
print(encrypted_text)
print(caesar)
# User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Challenge Information:
Build a Caesar Cipher - Step 10
new here too, but your first step would be organizing its properly within the new function body, you should be getting errors in the righthand side window which you will learn to resolve issues very quickly with the information later.
a hint i can tell you is that python uses indentations and spaces to organize and execute the code in a propper order, so really you just need to make sure everything is executing in the order its intended to. if you were to go back to your previous step you would see that the formatting has changed and thus the code will not execute in the order its meant to.
I have not the slightest idea of what you mean
python code blocks are formatted and executed using line indents. typically four spaces, or the tab key is also equal to four spaces. on the right side of your screen should be a black window reading some kind of indentation error text.
that makes sense since your code is currently organized in a way that nothing is actually inside a block, its just a list of lines of code and i can see one line has a single space indent.
what i mean is, when it says to put it in the function body, it wants you to organize it all into a code block. im not sure if thats strictly the same thing but i think it is, atleast for my understanding and the way i responded to you i meant the same thign.
So are u saying I should delete the line indent
okay, in python, a propper indent would be created by pressing the tab key, or else hitting space bar 4 times.
if you want to organize your code properly inside a functions body its done with line indents.
a single space is not a correct indent for python so the code isnt in a function body.
1 Like
If i delete it shows error in line3 if i dont shows error in line 5
well a single space isnt a proper indent to begin with so if you want everything you have written so far inside of a function body, that is done with line indentation.
if you stop indenting the lines it will return that line to the main script body.
if i was you i would look at some other threads just to see an example of how a function definition would have its code organized in the body using line indents.
i guess you have to wait 24 hours to reespond. i had the same thing. hope you ask more questions as you finish the class because it will help me reinforce what I already learned.
currently i am a little ahead of you and i am stuck on the assignment change user settings or whatever it is lol.
oh that assignment is one comming up for you, called,
a lab, user configuration manager.