#Python

1 messages · Page 1 of 1 (latest)

hexed epoch
#

just need some help on how to properly make my code work correctly (total beginner) dm if anyone would want to help thank you.

violet halo
#

@hexed epoch send your code

hexed epoch
#

okay

#

Step 4: Print a bullet list of pizza toppings

print_pizza_toppings(about_me)

print(f"*{about_me['pizza toppings']}")
#

i think im suppose to be adding a for and in statement

#

but im not sure how to make it with only one variable

#

he gives us this example

#

TODO: Print a dash list of all player names

for player_name in team ['players']:
    print(f'- {player_name}')
crimson pier
#

You'd do the same thing as in the dash list

hexed epoch
#

im just not understand where the 2nd variable is comign from if that makes sense

crimson pier
#

You got the about_me which contains the key of pizza_toppings, which I'm gonna guess is the list of the toppings

#

Second variable?

hexed epoch
#

sorry imr eally new to this 1 sec

#

let me try to explain it better

crimson pier
#

You mean ['players']?

hexed epoch
#

his example

#

what he gave us

#

(yop line)

#

top*

crimson pier
#

!formatting

rustic summitBOT
#
Code Formatting

When sharing code with the community, please use the correct formatting for ease of readability.

Example

```py
YOUR CODE HERE
```

Those are back ticks not single quotes, typically the key above TAB

crimson pier
#

And could you share more of the task?

hexed epoch
#

sure

#

do you want a screen shot or copy and apste?

crimson pier
#

Copypaste, using a code block would be preferred

hexed epoch
#

ok idk exactly what code block is but ill just copy and paste and hope thats right

#

Description:
Uses a complex data structure to store information about me.

Usage:
python about_me.py
"""
def main():
# Step 2: Create a complex data structure that holds information about me
about_me = {
'name': 'Wade Manley',
'student id': '65160657',
'pizza toppings': [
'SAUSAGE',
'PEPPERONI',
'BACON'

    ],
    
    'movies': [
        
        {
            'title': 'law abiding citizen',
            'genre': 'action'
        },
        
        {
            'title': 'underworld',
            'genre': 'action'
        }

    ]
}

print_student_name_and_id(about_me)
print(f"My name is {about_me['name']}, but you can call me Sir {about_me['name'].split()[0]}")
print (f"My student ID is {about_me['student id']}")

# Step 4: Print a bullet list of pizza toppings
print_pizza_toppings(about_me)

print(f"*{about_me['pizza toppings']}")
crimson pier
#

The quotes are backticks

rustic summitBOT
crimson pier
#

Copy the example from the formatting message, and replace the your code here with the code

#

So, you're supposed to create functions?

hexed epoch
#

thats what im trying to make

#

i understand how to write but i dont understand exactly where he pulls the 'team' from to make the list

crimson pier
#

That would be what your about_me is

hexed epoch
#

right

crimson pier
#

See how the print you have, and the team are formatted the same way?

hexed epoch
#

yes

crimson pier
#

about_me['pizza toppings']

and

team['players']

#

How would you modify the for-loop to use the one you have instead?

hexed epoch
#

oh

#

so itd be for pizza toppings in about)me

crimson pier
#
def main():
    # Step 2: Create a complex data structure that holds information about me
    about_me = {
        'name': 'Wade Manley',
        'student id': '65160657',
        'pizza toppings': [
            'SAUSAGE',
            'PEPPERONI',
            'BACON'

        ],

        'movies': [

            {
                'title': 'law abiding citizen',
                'genre': 'action'
            },

            {
                'title': 'underworld',
                'genre': 'action'
            }

        ]
    }

    print_student_name_and_id(about_me)
    print(f"My name is {about_me['name']}, but you can call me Sir {about_me['name'].split()[0]}")
    print (f"My student ID is {about_me['student id']}")

    # Step 4: Print a bullet list of pizza toppings
    print_pizza_toppings(about_me)

    print(f"*{about_me['pizza toppings']}")
#

These lines imply you'd have to create functions for those two:
print_student_name_and_id(about_me) and print_pizza_toppings(about_me)

crimson pier
hexed epoch
#

the toppings right

crimson pier
#
about_me = {
        'name': 'Wade Manley',
        'student id': '65160657',
        'pizza toppings': [
            'SAUSAGE',
            'PEPPERONI',
            'BACON'

        ],
hexed epoch
#

'pizza toppings'

#

no?

crimson pier
#

Yup

#

How did you get the name or student id previously?

hexed epoch
#

print_student_name_and_id(about_me)
print(f"My name is {about_me['name']}, but you can call me Sir {about_me['name'].split()[0]}")
print (f"My student ID is {about_me['student id']}")

crimson pier
#

These two lines will cause you to get a NameError:
print_student_name_and_id(about_me) and print_pizza_toppings(about_me)

#

You do not have those functions in your code

hexed epoch
#

but when i put it in it works fine

crimson pier
#

Did you run the code?

hexed epoch
#

yes

#

oh wait

crimson pier
hexed epoch
#

sorry you meant the line after

#

i thought u meant just those 2 lines

crimson pier
#

NameError: name 'print_student_name_and_id' is not defined

#

Those two lines will cause the NameError to appear

#

The ones I mentioned

#

You can comment those out

#

You don't have the functions named print_student_name_and_id or print_pizza_toppings

#

But, about the for-loop

hexed epoch
#

thats very strange because all the yellow is what our teacher put in to format this for us

crimson pier
#

Your teacher probably wanted you to create functions for the printing

#

But, the for-loop

#

How would you access the pizza toppings list that you have in the about_me?

hexed epoch
#

about-

#

woops

#

about_me['pizza toppings']

crimson pier
#

Now, how would you iterate through that list, with the for-loop?

#

for item in iterable: is the basic syntax for a for-loop

hexed epoch
#

for 'pizza toppings' in about me

#

or is that wrong

crimson pier
hexed epoch
#

no

crimson pier
#

about_me['pizza toppings'] This is the list you want to iterate through

hexed epoch
#

yes

crimson pier
hexed epoch
#

okay yes that means they can looped over and over

crimson pier
#

What would the for-loop look like if you iterated through it?

#

You do have the sample your teacher gave you

#
# TODO: Print a dash list of all player names
for player_name in team['players']:
  print(f' - {player_name}')
hexed epoch
#

for {about_me['pizza toppings'] in about_me

crimson pier
#

about_me['pizza toppings'] This is a list containing items

#

Or in other words: Iterable containing items

hexed epoch
#

oh ok so

crimson pier
#

Look at the example your teacher gave you

#

What's different between that, and the last for-loop you sent?

hexed epoch
#

for toppings in about_me['pizza toppings]:

crimson pier
#

There you go

hexed epoch
#

YAYA

#

THANK U

crimson pier
#

You're just missing quotes

#
for toppings in about_me['pizza toppings']:
hexed epoch
#

ok ok thank u so much lol

#

idk why but coding is so hard for me

crimson pier
#

We do have resources that are beginner friendly that might help you learn a bit more

#

!r

rustic summitBOT
crimson pier
#

And, understanding the basics before jumping into larger projects is something that's really useful overall

hexed epoch
#

yea i just dont have a lot of time to do this coding so im sturggling

#

my semester is packed with assignments and this is one of my classes

#

that i sturggle with

crimson pier
#

w3schools is a great site for resources

#

They have pretty clearly written examples and information about the basics of Python

hexed epoch
#

okay i just favourited that

#

thank you though alot