 Hey guys, so right now I'm going to be going over functions lab one solutions for problem two So this is giving us a couple different functions and then we are Trying to see what's going to happen when we're given specific values to be inputted into our function So if we start with 2.1, I've already put it in here. We have The function foo it takes one input Which will be an integer and it's going to return an integer to us which we can see our return type here Our input here and then what's going to be returned down here So if we call foo and if we put in 47 we know that We can kind of figure out what's going to be outputted without even having to call it Just by seeing what's happening. So when we call foo It's going to input 47. So now our input a our integer a is going to be equal to 47 So then we come into the code here and what's going to be returned to us is 47 modulo 10 Which we know from Foundations to programming that that's going to give us back the answer 7 So we can run that and double-check and we can see it's 7 So now if we want to see 283 We'll do the same thing is what's going to happen with 47. We're going to call foo This integer a is now going to be equal to 283 and 283 modulo 10 is going to be equal to 3 So you can see that down here and if you replace this with a zero We're going to get back the input zero a is going to be equal to zero zero modulo 10 will be zero so we can Call this many different times with all of the inputs actually Kind of see what's going to happen. I'll fix some of my spacing 47 283 and I'll print them all on new lines So now when we run this we can see all of our outputs down here 7 3 and 0 so this local variable a Is being re-initialized every time we call the function foo and it will be Equal to whatever input we're telling it to be equal to And then it's going to do whatever code we we wrote in this function in between these two curly brackets And then it's gonna return a specific integer to us. So it's kind of the basics of what's happening For this problem. So if we go on to 2.2, we've got this new function called bar We can see bar is taking in one input a and that input needs to be an integer And then it's going to return an integer to us So now we can come in here and we can call bar With our first input 47 And by printing this it's just allowing us to see what the output is going to be So we could just call it and put our inputs in but it's we're not telling anything to be done with these Inputs so by printing it where it's just allowing us to see what's What the output is going to be So we know that a is now going to equal 47 And this is a local variable for bar So we've got an integer a for foo and we've got a local or a local integer a for bar But these are actually two separate variables. They're not They're not related in any way. So every time we call foo We have a new integer a that's being initialized and we've every time we call bar We've a new integer a that's being initialized as well So we can call bar with this integer or with the integer 47 It'll be in Inserted into this local variable a and that variable a can only be used within that function So the a in here Is not related to this a because there's something they can only use their local variables within their own function So we've got this integer a it'll be equal to 47 47 divided by 10 is going to equal to 4 When we run that We can see that right down here And I'll just print a bit of a space just so we can kind of see what's happening There we go. That gives us a bit of a spacing in between each problem So now we can run this again with our with our next input Which is 283 So we know that 283 is gonna Be or we're gonna call bar with the input 283 So we'll do 283 divided by 10. It's gonna be equal to 28 We can check that right down here 28 that's all correct and then Our last input with zero Zero is gonna be into we're gonna call bar Where you're going to give it the input of zero. So now a is equal to zero zero divided by 10 Is gonna give us the solution of zero We can see that right down here So now let's take a look at our last function So I've got a bit more of a complicated function called chi. All right, we can see that down here I'll actually just put it right at the top so we can see it a bit better There we go. So now if we call chi with our first input 47, we're gonna call chi We're gonna give it the input 47. So now this local variable a is gonna be equal to 47 And remember this a has no relation to These other integer a's because it's a local variable. It can only be used within its own function So now a is gonna be equal to 47 And then we've got a new Variable being initialized as well. And this is also a local variable It's gonna be an integer called b and we're gonna call foo a So we're gonna We know that our a is equal to 47 So we come down here We're gonna call foo with 47 So we know that foo 47 was equal to 7 so we're gonna be returned 7 So now b we can write that here. We know that b is gonna be equal to 7 and Then if b is less than 5 we're gonna return something else. We're gonna return something else So we know that b is not less than 5. So we're gonna return whatever this else is Which is a? Which we know from up here is 47 Minus b, which is 7 plus 10 So the value that should be returned to us should be 50 and we can see that right here So again, I know these kind of get start to get a bit complicated But just writing out some different comments or writing out on a piece of paper What's going on is really helpful So now we'll do this again with Was it 283 so we come into here and we know that a Is gonna be equal to 283 and Then we know that b is gonna be equal to foo of a which is 283 So we know that foo of 283 is gonna be equal to 3 so we know that b will be equal to 3 and B is less than 5 so we're gonna return 283 Minus 3 so we should get back the value 280 We can run that and check and we're correct so our last one is Trying it out with zero and delete all these comments So start we know that we're gonna call chi with the input zero. So now a is gonna be equal to zero B is gonna be equal to foo Zero which we know is equal to Zero come down here and call foo with zero. It'll return to us zero And zero is less than five so we're gonna be given zero minus zero Which will be equal to zero so we should get the value zero return to us and we do So this is just one way you can kind of test out different functions and see what is being returned to them Again, if you are struggling with any of this or you don't know what's going on try using the debugger So like for example, we can come on here and we'll just put a break point on each of the Inputs of 47 to kind of see what's happening So let's see if this works So we can run this So we're first halted at Our first break point and then we'll see kind of jump from there That's instead Actually, let's try stepping into instead So we'll run this off. That's not working. Is it that's instead put this into an Integer and Same with these ones This is just me giving random integer values so we can actually use the debugger and see what's happening All right, so let's fix our Breakpoints and then we'll put a breakpoint value on each of the return as well All right, let's try this again So we can run this we're halted at this first integer M We'll step in so now we call foo so we go into foo And we can see that it's coming into here and then we step back up here And then go to if I see now now we can go into the functions So we'll just continue to our next breakpoint which is n and Then we hit this end and we're gonna call bar 47. So now we should jump into 40 error bar function You can see we're gonna jump into here We'll continue out of it. We now hit this integer L and we're gonna call cheat of 47 We now there we go. We now jump into cheat and As we knew from before we hit this else return value So that's why we're skipping this return value and we're jumping down to this return value So you can use the debugger as kind of a way to see what's going on Just mess around with the debugger a bit But just make sure you're stepping into the functions to kind of help you understand what's going on So hopefully this helped you guys