Build a Pin Extractor - Step 16

Tell us what’s happening:

hello can some one till me what is the problem i know its on the global part but i want someone to explain it to me and thanks

Your code so far

def pin_extractor(poem):
    secret_code = ''
    lines = poem.split('\n')
    for line_index, line in enumerate(lines):
        words = line.split()
        if len(words) > line_index:
            secret_code += str(len(words[line_index]))
        else:
            secret_code += '0'
    return secret_code

poem = """Stars and the moon
shine in the sky
white and
until the end of the night"""



# User Editable Region

global poem2 ='''The grass is green\n
here and there\n
hoping for rain\n
before it turns yellow'''

global poem3='There\nonce\nwas\na\ndragon'

print(pin_extractor)

# 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/147.0.0.0 Safari/537.36

Challenge Information:

Build a Pin Extractor - Step 16

The global keyword is used to reference a global variable in another function; so it can be modified. Without the global keyword all variables will be treated as local.

ok i wrote it like this global poem2

poem2 =the text

global poem3

poem3=the text

print(pin_extractor(poem))

what is the problem now

Hi @hassan12,

Please just follow the instructions. You only need to add two more poems.

Look at the poem variable in the starting code. There is no global keyword and there are no newline characters because the text is surrounded by triple quotes. Pattern your new poems like that one.

You also did not comment out the print as asked. In fact, you changed it.

Edit: About global scope. This is an excerpt from the reference provided: “Global variables are declared outside all functions and can be accessed anywhere in the program, including inside functions.” Global and Local Variables in Python - GeeksforGeeks

Happy coding!