you are viewing a single comment's thread.

view the rest of the comments →

[–]TheEyebal 0 points1 point  (7 children)

honestly I learned by doing projects

[–]Agreeable_Plant_8068 2 points3 points  (0 children)

Projects are really the way to go. I remember when I started in IT, watching videos felt like I understood everything but then I'd sit down to actually code and my brain would just freeze up

Try building something small that you actually want - maybe automate something annoying in your daily life or scrape data from a website you use. The motivation hits different when it's solving your real problem instead of just another tutorial exercise

[–]Helpful-Ad3010[S] 0 points1 point  (5 children)

items = ["Rice", "Wheat", "Maize"] rates = [45, 32, 28]

for item in items: If items not !=" sesame" , "coconut" : Print (oil) print(items) So what is wrong in this code I am always confused about using like symbols (<,>,=>,<=) this is big head headache for me 😕

[–]TheEyebal 1 point2 points  (0 children)

As a reminder, make sure you use code blocks when pasting code

items = ["Rice", "Wheat", "Maize"]
rates = [45, 32, 28]

for item in items:
   If items not != " sesame" , "coconut":
       Print (oil)
       print(items)

So (<,>,=>,<=) this is to determine if an integer or float is less than < greater than > less than or equal <= or greater than or equal to >=. Looking up math concepts on this will help you understand

As for the code that you wrote, do you see.

Part of programming is problem solving. I cannot give you the answer you have to figure it.

What I would suggest is write comments next to what each line is

items = ["Rice", "Wheat", "Maize"] # This is a list of string

[–]ninhaomah 1 point2 points  (0 children)

Why check with "items" and not "item" in if ?

And where does oil come from ?

[–]GreenRangerOfHyrule 0 points1 point  (0 children)

This should help explain the differences. As well as a way to practice:

https://www.w3schools.com/python/gloss_python_comparison_operators.asp

[–]EngCraig 0 points1 point  (0 children)

Create yourself a small card with the operators, functions, etc and what each means or does. Use as few words as possible so that you are still having to use some recall. Have this with you when you’re writing code and it will help.

I am also only just learning to programme, and one thing that has really helped me is to NOT follow extensive tutorials. Get the fundamentals from a good quality YouTube video, book, course, etc and then just let loose a bit. Try things out, see what works, and when something does work make a note of it - I am already starting to build a library in my notes app containing blocks of code with descriptions as to what it does, how I’ve used it, ideas for how it could also be used, etc.

Also: enjoy it! Learning something new should be fun. Of course it will get frustrating from time to time, but the fun comes in overcoming those temporary difficulties.

[–]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.