What is this code meaning & how can I understand it

Guide me in simple English
a = 3
b = 9
if b % a == 0 :
print (“b is divisible by a”)
elif b + 1 == 10:
print (“Increment in b produces 10”)
else:
print (“You are in else statement”)

You are posting a few of these questions without any real context? Where is this code from? Are you following a particular Python course?

You may find it useful to follow the FCC Scientific Computing with Python course.
It is a beginner course which should give you a good understanding of all of these Python fundamentals.

1 Like

Is it a free course? Or paid course

All of the FCC courses are completely free.

I am trying to say please explain the code

Its much easier to help if you explain what you understand

2 Likes

help me in simple English
I’m nothing to understand sometimes double “is equal to” is coming I don’t know why it is coming
immediately “%” percentage is coming
than divisible by is coming…
I can’t understand what is the connection between these all three

If you don’t understand anything about this code, you obviously didn’t write it. This isn’t a place to just copy random code and ask for it to be explained. It’s easier to understand code if you wrote it yourself.

== You are correct, this is checking if one value “is equal to” another and returns True or False (unlike = which is assigning a value to a variable)

% is modulo it returns the remainder of a division. 9/3 = 3 remainder 0.

You should start with the Scientific Computing with Python course to explain it all from the beginning: https://www.freecodecamp.org/learn/scientific-computing-with-python/python-for-everybody/introduction-why-program

Complete the Python for Everybody course and you will learn a lot.

If I understand this code, there is no chance coming for your assistance

We are here to assist in genuine problems encountered when solving problems, when you are stuck. It’s up to you to start learning on your own.

You could paste this into chatGPT and it could explain a lot for you, that might help.

Or you can start the course here:

https://www.freecodecamp.org/learn/scientific-computing-with-python/

1 Like

It really helps if you learn the fundamentals through some sort of course instead of trying to figure out what scraps of code do

Python is actually famous for being easy to read.

I’d really recommend following a beginner Python course. It’s not tough to learn the basics. The FCC beginner Python courses are video tutorials but if that’s not suitable for you, you could also try https://www.py4e.com/ which is created by Charles Severance, who created the FCC course. It’s all free and there are many different ways to learn!

1 Like

what you said that all I understand
but a last small doubt what is “if else elif”. In chat GPT I asked
It said like this
It said if condition1:
# block of code to execute if condition1 is true
elif condition2:
# block of code to execute if condition2 is true
elif condition3:
# block of code to execute if condition3 is true
else:
# block of code to execute if none of the conditions are true.

Why is condition 1st true or false 2nd true? blah blah blah
Is single line command not enough?
When will use this code, these are my doubts. Please clarify. Thank you

As more than a few people have already suggested. The best thing for you to do is to start going going through the python course they have gave you a link to. When you go through the course they will teach you about the doubts you have. If you are still unsure while going through the course then you can ask for clarification.

1 Like

haha… I had a good laugh about “coming”…

So, you need to understand the following:

  1. basic syntax (if this is python) then here Python Numbers
  2. Python numebers
    infact the link above, if you do those topics, within a week you will know e xactly and more.

now,

a = 3 mean, a is a variable and the equal to sign means, that the value of 3 has been “assigned” to the variable a. Hope this makes sense.

when we want to say, this apple is exactly equal to that apple, then in code we don’t use the “=” sign. Why? because we already used it for “assigning” a value. So now we have to come up with another “code”. So in the world of coding, the gran daddy’s decided, you know what, lets agree taht when we use the equal to sign “=” twice, then it would mean, that we are saying that 2 = 2. i.e 2 is equal to two. In the normal world, that is a truthful statement. Yes, 2 is really equal to 2. so we say, 2 == 2.

ok so now that we have tackeld = and == what is this “%” sign “coming?”…

its “coming” because this is not the DIVIDE by sign. Instead , in coding this is called the “modular” in maths, it means, what is the “remainder” … so if you were to divide b (which in this case is now 9) divide by a (which in this case is equal to or has been assigned the value of 3) there will be “0” remainder. no fractions. So suppose 9 means, 9 pieces of pizza. And you are 3 friends. So you gave everyone 3 pieces. You burped and nothing was left on the plate… and nothing was coming … only going in…

hope it makes sense …

1 Like

If, else, else if are all part of basic programming courses. Skipping the basics drastically cripples your learning