#Python-Dictionary
71 messages · Page 1 of 1 (latest)
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
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
can i ask what sets are for
when would you use those
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...
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
How's that related? 💀
I'm saying he should use an array instead of dictionary
Not prices the menu
Looking at code he was using dictionary to index the input from the user
But it's wrong
I have no idea what you're talking about, are we looking at the same code? 💀
Check his data dictionary
he made some modifications though?
btw those are not the prices
im setting numbers to each item in the menu
Fair enough
Thank you
That's what I wanted him to know
whats the command
Just use the array you created first
not yet😭
It's indexed starts from zero so of user inputs 1 subtract one from any user input
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
so lets say a customer wants a cappuccino
theyd have to pick 2
if they want an americano theyd have to pick 6
No need for that
Use the index
If user inputs 2 the index is 1 so subtract one from user input
You know programming starts counting from 0
Copy and paste your code let me help you on it
Yeah
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
yeah my tutor accidentally showed the class his code and its what he used. but i dont wanna use it since we havent been taught that yet
probably gonna get taught that next week
Ooh cool
But Don't wait for the class explore
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
Alright 👍
Best luck
I'm a student also
You can reach in dm too
thanks
!rule dm
The point of using these help channels is that multiple people can help
makes sense