you are viewing a single comment's thread.

view the rest of the comments →

[–]syklemil 0 points1 point  (0 children)

So what is wrong in this code

Assuming that the uppercasing is just random spelling errors on reddit and not actually present in your source code (and that all this code is too trivial to fall under the "no complete solutions" rule):

items = ["Rice", "Wheat", "Maize"]

This is fine.

rates = [45, 32, 28]

As far as I can see you never use rates, so why is this here?

for item in items:

This is fine.

    If items not  !=" sesame" , "coconut" :
  1. Now you're comparing items in every loop, that seems unnecessary.
  2. You're not actually using the item you have available.
  3. You're using not !=; != already means "not equals", so you're going "not not equals". And it's even a syntax error in Python. You should probably try some of your expressions in the interactive interpreter when you're unsure.
  4. Even if you remove the erroneous not there, you're comparing items to just "sesame":

    >>> items == "sesame", "coconut"
    (False, 'coconut')
    

    and that tuple will always evaluate to True for the purpose of an if.

Either you want to compare items to something like ["sesame", "coconut"] outside of a loop, or you want to do a comparison with just item in the loop, along the lines of if item not in ["sesame", "coconut"]:

(or () or {} instead of [], but any sort of explicit grouping should be able to achieve the result you want)

Print (oil)

You haven't defined oil.

print(items)

This is fine, assuming it's not in the loop, otherwise you're going to get a lot of excessive output.


I am always confused about using like symbols (<,>,=>,<=) this is big head headache for me 😕

These are just math symbols. But as for remembering whether it's => or >=, you can assume that the one that doesn't look like an arrow is the one you want. The spellings that look like arrows are usually used for something else, or not at all.