#Python
1 messages · Page 1 of 1 (latest)
@hexed epoch send your code
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}')
You'd do the same thing as in the dash list
im just not understand where the 2nd variable is comign from if that makes sense
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?
You mean ['players']?
!formatting
And could you share more of the task?
Copypaste, using a code block would be preferred
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']}")
The quotes are backticks
@crimson pier
Cannot parse: 1:12: Description:
Copy the example from the formatting message, and replace the your code here with the code
So, you're supposed to create functions?
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
where as im only given this https://i.gyazo.com/thumb/1200/19c6dab8a91fe3758041fff2086dc3e5-png.jpg
That would be what your about_me is
right
See how the print you have, and the team are formatted the same way?
yes
about_me['pizza toppings']
and
team['players']
How would you modify the for-loop to use the one you have instead?
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)
Almost, what item is the one you'd want to iterate through in your about_me?
the toppings right
about_me = {
'name': 'Wade Manley',
'student id': '65160657',
'pizza toppings': [
'SAUSAGE',
'PEPPERONI',
'BACON'
],
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']}")
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
but when i put it in it works fine
Did you run the code?
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
thats very strange because all the yellow is what our teacher put in to format this for us
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?
Now, how would you iterate through that list, with the for-loop?
for item in iterable: is the basic syntax for a for-loop
Does that contain this at all: about_me['pizza toppings']?
no
about_me['pizza toppings'] This is the list you want to iterate through
yes
Lists are iterables
okay yes that means they can looped over and over
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}')
for {about_me['pizza toppings'] in about_me
about_me['pizza toppings'] This is a list containing items
Or in other words: Iterable containing items
oh ok so
Look at the example your teacher gave you
What's different between that, and the last for-loop you sent?
for toppings in about_me['pizza toppings]:
There you go
We do have resources that are beginner friendly that might help you learn a bit more
!r
Here are some resources you may find helpful.
And, understanding the basics before jumping into larger projects is something that's really useful overall
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