Learn String Manipulation by Building a Cipher - Step 55

Tell us what’s happening:

I don’t understand this command for and how it works. I saw the forum put ‘text’ in the last caesar variable: caesar(text) and it works, but I don’t know the whole idea of this step.
please help me understand.

Your code so far

text = 'Hello Zaira'
shift = 3

def caesar(message, offset):
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    encrypted_text = ''

    for char in message.lower():
        if char == ' ':
            encrypted_text += char
        else:
            index = alphabet.find(char)
            new_index = (index + offset) % len(alphabet)
            encrypted_text += alphabet[new_index]
    print('plain text:', message)
    print('encrypted text:', encrypted_text)

# User Editable Region

caesar(text, shift)
def caesar():
    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/127.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 55

Hi @himenovs

Your code raised an error before any tests could run. Please fix it and try again.

You have already defined caesar so please remove the the following code:

Happy coding

I removed those code and it works.

This is what it said for this step:
Currently, your code raises a TypeError, because the caesar function is defined with two parameters (message and offset), therefore it expects to be called with two arguments.

Calling caesar() without the required arguments stops the execution of the code.

Give message and offset values, by passing text and shift as arguments to the caesar function call.

I don’t understand the bold command, my understanding is, how the code still works after passing “message” and “offset” value with “text” and “shift” arguments? because they are different variable.

def caesar(message, offset):

You can see here, in the function definition, that the function requires 2 values to run. This means you need to provide, or “pass” 2 values when you run or “call” the function.

caesar()

Currently we are calling the function and providing no values, so it will not be able to fun. We need to pass 2 arguments to the function. Here are some examples of this:

function(argument1, argument2)
print("The number is ", num)
print(a,b)
addNumbers(5,10)
def caesar(message, offset):

The function is defined with 2 parameters, message and offset. Within the function, this is how the values will be referred to, since they exist only within the function.

caesar(text, shift)

When you call the function, you provide 2 values. These happen to be in the form of variables but it could be like this as well

caesar("My sentence to encipher", 5)

Once you call the function, those values will be referred to as message and offset within the function since this is how you defined it.

1 Like