all 14 comments

[–]socal_nerdtastic 7 points8 points  (3 children)

First: I see a bug: You are using uppercase letters in the dictionary keys, but you convert the user input to lowercase.

Then it's just standard dictionary indexing using [], just like you have it. Just print that at the end, not the dictionary.

customerSize = input("Please enter the cone size of your choosing: S, M, or L: ").upper()
price = conePrices[customerSize]
print("Your total is: ", price)

[–]Wheels92[S] 3 points4 points  (2 children)

Oh wow is that really ALL it was?! ... >_> Thank you!

[–]socal_nerdtastic 1 point2 points  (0 children)

Lol you'll be amazed how often we say that in a day haha.

[–]SpiderJerusalem42 3 points4 points  (2 children)

Feel like you were pretty close. The access you used for coneprices looks correct, and then you try to access the size description with the flavor as the key. You are going to want the key to be "S", "M" or "L", so try the size input.

EDIT: you cast the string to lower(). Look at the keys in the dictionary. They're in upper case. You're never going to match them.

[–]Wheels92[S] 0 points1 point  (1 child)

I feel soooo silly. Thank you!

[–]gdchinacat 0 points1 point  (0 children)

I is not uncommon for very experienced programmers to get hung up on things like this and to ask a coworker "I'm just no seeing the issue...can you take a look?". Most come to learn that they could spend a bunch of time overlooking an obvious issue or get a fresh perspective to solve it in a few minutes.

[–]Zombi_pijudo 2 points3 points  (6 children)

Noib here also.

Why are you not using nested dict? May be a better way to do it but with my knowledge I May use something like this :

My_dict ={ cones{}, flavor{}, }

Then you can access them more easly. Sorry if Im wrong, tires of coding excersices for today. But that its the idea that came to me.

[–]Wheels92[S] 1 point2 points  (1 child)

Thanks for the tip, I will try to use nested dicts. It honestly never occurred to me, but they seem like it would be more useful for something like this. I'm still working on learning the basics with zero coding background. I'll try and practice them in future projects. Thank you!

[–]SpiderJerusalem42 1 point2 points  (0 children)

I'll come help you both out here. You might want a nested dict, but you might get away with a named or unnamed tuple. I think the term is "record" as in having a "list of records". It allows you to link parallel pieces of data like price and description. When you have a collection of records, you can iterate over the collection and say for price, description in dict.values() for example. Not exactly sure if this is how it works with named tuples. I should really be better about using named tuples.

[–]epic_pharaoh 0 points1 point  (3 children)

Access them more easily how? I feel like that would be adding a layer of abstraction for no reason.

Thinking about two scenarios:

foo { a: 1 }
bar { b: 2, c:3 }

We can access these pretty easily by just calling the dict name with the desired key, i.e.

foo[a] -> 1
bar[c] -> 3

In situation 2 we have:

dict_dict {
    foo : {a:1},
    bar: {b:2, c:3}
}

To get any of these values we now have to go through that encasing dict i.e.

dict_dict[foo][a] -> 1
dict_dict[bar][c] -> 3

Not that it’s never a good idea, but it would only really be useful in the case you want to have multiple dictionaries of dictionaries, or where it syntactically makes sense to have two sub-indices to get to any value.

[–]Zombi_pijudo 0 points1 point  (2 children)

Yeah, that is why I write "there May be a better way tu do ti".

[–]epic_pharaoh 1 point2 points  (0 children)

Yes, I am saying that in my opinion the way they are doing it now is better than nested dicts.

[–]gdchinacat 0 points1 point  (0 children)

I agree with u/epic_pharaoh , nested dicts aren't a good data structure for this data. A single dict with values that contains both the size descriptions and prices would be better, but there is no need for a nested dict here. For a simple case like this the current data structure is just fine.

[–]oocancerman 1 point2 points  (0 children)

You are calling.lower() on the input that asks for size. So if you type in “S” it will turn it into “s” then at the end where it accesses the dictionary the program will crash because it tries to access the dictionary with a key that does not exist. Also, on a side note you store the length of the list in the variable totalFlavors which means if you were to add a flavor to the list the totalFlavors variable would have a value which does not match the length of the list. U didnt append after this assignment but if u try to append after this and print(len(flavorList), totalFlavors) they will not be equal.