Hi this is my first post, I am learning how to write code so technically I am a newbie.
I am learning python I am still at the very basics, I was getting to Know the if statement and I tried to mix it with another concepts(function definition,input,variables) in order to get a wider vision of python, I wrote some code without a specific idea of what I wanted to do I just wanted to mix everything that I have learned so far so probably I over do it and its not practical, it "works" when I run it.
The question that I have its not about how to do it more efficient or with less code it is about the order of code in all programming in general. Here I'll show 2 different order of code that gives the same result with exactly the same code(but with different order).
on (1) I define a function on the first line.
on (2) I define the same function closer to when I use it on line 5.
which one is faster? is defining a function "closer" to when I need it impractical for the complexity of larger programs(but does it make it faster), or defining a function "far" from where I need it makes a larger program slower when running(but also more practical).
(1)
def t(n1,n2):v=n1-n2return abs(v)
a = int(input('how old are you? \n'))
b = int(input('how old is your best friend? \n'))c=t(a,b)if a==b:print ('you are both the same age')else:print('you are not the same age\nthe difference of years is %s year(s)' % c)input()
(2)
a = int(input('how old are you? \n'))
b = int(input('how old is your best friend? \n'))def t(n1,n2):v=n1-n2return abs(v)c=t(a,b)if a==b:print ('you are both the same age')else:print('you are not the same age\nthe difference of years is %s year(s)' % c)input()