#Python-Dictionary

71 messages · Page 1 of 1 (latest)

sour moth
#

Hi im getting an error on python when i try making a dictionary, ive tried asking chatgpt but it doesn't understand. Perhaps someone could tell me what im doing wrong?

#

for context its meant to be a menu of a coffee shop, i've made a #list now im trying to set numbers to each product in the list

#

i havent learn much about dictionary, so im not 100% sure if its the right thing to use here to assign a number to each product on the menu

#

heres what ive done so far

#

and this is the error i am getting

minor elm
#

You are using the set notation here

#

Sets look someting like this:

my_set = { 'some value', 'some other value' }

While dicts look something like this:

my_dict = { 'some_key': 42, 'some other key': 'some value' }
#

So you should have the price for each item right after the item, not in a list after all items

sour moth
#

oooh alright

#

thanks

sour moth
#

when would you use those

minor elm
#

Python sets are more or less the math sets

#

In mathematics, a set is a collection of different things; these things are called elements or members of the set and are typically mathematical objects of any kind: numbers, symbols, points in space, lines, other geometrical shapes, variables, or even other sets. A set may have a finite number of elements or be an infinite set. There is a uniq...

bold rain
#

Dictionary goes with value and key

#

It better to make it an array which is indexed and because we type using 1 you decrease the user input by one

bold rain
#

I'm saying he should use an array instead of dictionary

minor elm
#

For the prices? Hell nah

#

For the menu options: Maybe but meh

bold rain
#

Not prices the menu

#

Looking at code he was using dictionary to index the input from the user
But it's wrong

minor elm
#

I have no idea what you're talking about, are we looking at the same code? 💀

bold rain
#

Check his data dictionary

minor elm
sour moth
#

im setting numbers to each item in the menu

minor elm
#

Fair enough

sour moth
#

its like those screens you see in mcdonalds

#

to order food

bold rain
#

That's what I wanted him to know

sour moth
bold rain
sour moth
bold rain
#

It's indexed starts from zero so of user inputs 1 subtract one from any user input

sour moth
#

oh wait

#

i think im catching on on waht you're thinking

bold rain
# sour moth

Take out the data dictionary and maintain only menu

sour moth
#

where it says if user input 0: print "return main menu"

#

thats a different section

#

im trying to assign a different number to each item in the menu

sour moth
#

theyd have to pick 2

#

if they want an americano theyd have to pick 6

bold rain
#

You know programming starts counting from 0

#

Copy and paste your code let me help you on it

sour moth
#

i cant rn i have python on my laptop

#

im on a diff device rn

sour moth
bold rain
#

I have a better version of your code idea in my head
I really wants to help you debug
You can even use a for loop to number them so that there is no need to tell the user to input a number but rather pick a choice

sour moth
#

probably gonna get taught that next week

bold rain
#

Ooh cool
But Don't wait for the class explore

sour moth
#

you right

#

but

#

its late where i am and class starts early tomorrow

#

so i have no choice😂

#

ill be back after class tomorrow if thats fine with you

bold rain
#

You can reach in dm too

sour moth
sour moth
#

im going to sleep now

white locust
azure ridgeBOT
#
Direct Messages

Please keep discussion on the server. It helps you get responses more quickly from more people & with more viewpoints. It also helps protect you from scammers.

We recommend disabling DM's from all public servers.

white locust
#

The point of using these help channels is that multiple people can help

sour moth
#

makes sense