Indent


#1

when do you know to indent and if you are decoding a code what does an indent mean if you see it?


#2

You will see indents underneath functions, loops, etc. For now, I wouldn't worry so much about it. As you get more practice with coding you will know when to indent. For example:

def adding(a,b)
[indent 4 spaces] return a + b

adding(2, 5)

The indent lets the code know to only return a + b when the function (adding) is called. So 2 + 5 will be returned only if the function above it is called. Not the best explanation, but I hope it helps.


#3

okay thank you! what if the problem was

x = input ("Enter an id: ")
y = (x % 5 + 17) * 2
print x
print 'Check ', y

id= 16
what would the output look like
sorry for asking i just have a computer programming final on this in an hour


#4

Um. The output would be 36. I'm assuming input returns a given number as an integer. So 16 modulo (is same placement as * and / in the order of operations) 5 is 1 because 5 goes into 16 3 times and leaves a remainder of 1. Then you add one to 17. Then you multiply by 2. Print will print 16.


#5

And I just ran it. It is 36.


#6

So, you don't need to indent here because your not dealing with functions. Your dealing with variables. The variable y is modified with the given input of 16 or whatever id is. Also, study earlier man.


#7

thank you that really helps!