# Tutor profile: Nathan P.

## Questions

### Subject: Python Programming

If I want to make a list of numbers that contains every third number from 0 - 100 exclusive in reverse order, how would you do it? Now apply a function that multiplies every number in that list by 4. How would you do that.

For every step of the process i have provided two different ways of approaching the problem: Get List of every 3rd Number from 0 - 100: Method 1: list comprehension and splicing. oddNum = [i for i in range(100)][::-3] Method 2: range function with multiple paramters oddNum = list(range(0, 100, 3))[::-1] # this gets an iterator of ever third number from 0 to 100. Then it gets the list and finally using the slicing opperator [::-1], reverses the list ----------------------------------------------------------------------------------------------------------------------------------------- Create a function that returns 4 times the input parameter: Method 1: normal function definition To apply the function to the entire list, first create the function. def quadruple(x): # the name of the function is quadruple return x *4 Method 2: Lambda Functions quadruple = lambda x: x * 4 ----------------------------------------------------------------------------------------------------------------------------------------- Multiply every element of the list by 4: Method 1: List comprehension again now to apply quadruple fn to every element of the list oddNum, you can use another list comprehension like so: oddNum = [quadruple(elem) for elem in oddNum] Method 2: Map function oddNum = list(map(quadruple, oddNum))

### Subject: Java Programming

What will the JVM print if the following you call the following method: public static void equalityCheck(int a, int b) { if (new Integer(a) == new Integer(b)) { System.out.println("EQUAL"); } else { System.out.println("NOT EQUAL"); } }

It will print EQUAL if a and b are in between the values of -127 and 128, else it will print NOT EQUAL. This is because Java does something call Autoboxing and Unboxing. This is where certain classes, such as Integers are wrapped in a Class and thus the '==' operator that checks for a object equality fails. However, numbers between -127 and 128 are cached such that they are understood as primitives and when the '==' operator is used on primitives, it checks for value equality, not reference equality.

### Subject: Algebra

How would you reduce the following fraction? $$\frac{4*(2x-1)(x-3)}{12x^2 -52x + 48}$$

We are given the fraction $$\frac{4*(2x-1)(x-3)}{12x^2 -52x + 48}$$. First factor the bottom so we can attempt to simplify: $$12x^2 -52x + 48 = 4(3x^2 - 13x + 12) = 4(3x - 4)(x - 3)$$ We can now say that $$\frac{4*(2x-1)(x-3)}{12x^2 -52x + 48} = \frac{4*(2x-1)(x-3)}{4(3x - 4)(x - 3)}$$. Cross out the $$4$$ and $$x-3$$ on top and bottom to get $$\frac{2x-1}{3x - 4}$$ Thus, $$\frac{4*(2x-1)(x-3)}{12x^2 -52x + 48}$$ simplifies to $$\frac{2x-1}{3x - 4}$$

## Contact tutor

needs and Nathan will reply soon.