Quastions about " if " with functions


#1

Hi there!
I am trying to understand how to configure some calculation ,
lets say i have this code:

first = 2009

if first == 2009 :
print (2 * 8)
elif first == 2010 :
print (3 * 7)
elif first == 2011 :
print (4 * 6)
elif first == 2012 :
print (5 * 5)
elif first == 2013 :
print (6* 4)
elif first == 2014 :
print (2 * 3)
elif first == 2015 :
print (2 * 2)

last = 2011

if last == 2009 :
print (1 * 2)
elif last == 2010 :
print (21 * 3)
elif last == 2011 :
print (2* 4)
elif last == 2012 :
print (4* 5)
elif last == 2013 :
print (5 * 6)
elif last == 2014 :
print (6 * 7)
elif last == 2015 :
print (1 * 8)

Each time i am changing the values "first" or "last" i will get some other result,but how can i save that result with some function or variable?
What i need is a way to calculate "first" result + "last" result ,and to do that i need to somehow put each of those variable into a function or other thing that can "save" them...

Tnx :wink:


#2

//I am using 2 functions here and the results are stored in lists. So you can use it later. Hope this helps

def func_first(first):
if first == 2009 :
return(2 * 8)
elif first == 2010 :
return(3 * 7)
elif first == 2011 :
return(4 * 6)
elif first == 2012 :
return(5 * 5)
elif first == 2013 :
return(6* 4)
elif first == 2014 :
return(2 * 3)
elif first == 2015 :
return(2 * 2)
def func_last(last):
if last == 2009 :
return(1 * 2)
elif last == 2010 :
return(21 * 3)
elif last == 2011 :
return(2* 4)
elif last == 2012 :
return(4* 5)
elif last == 2013 :
return(5 * 6)
elif last == 2014 :
return(6 * 7)
elif last == 2015 :
return(1 * 8)
solution_first=[]
solution_last=[]
for i in range(0,5):
first=int(input("Enter first : "))
last=int(input("Enter last : "))
solution_first.append(func_first(first))
solution_last.append(func_last(last))
print(solution_first)
print(solution_last)


#3

When you try it, remember to use proper indentations


#4

Hi, thank you very much!
I still didn't understand what is the "command" for getting the results of the first function + the second one,
The code you gave me includes that?
all i need is to print at the end something like :
func_last(2012) + func_first(2014) = - the result - it should be not 2012 +2014, it should be (4*5)+(2*3)...

Tnx!