TutorMe homepage

SIGN IN

Start Free Trial

Aaron L.

Research Assistant at Stanford University, Code/Math Tutor for 2 years

Tutor Satisfaction Guarantee

Python Programming

TutorMe

Question:

Given an integer $$n$$ $$(n>0)$$, write a method which computes $$n!$$ (n factorial). For reference, $$n!$$ would be calculated as $$n \cdot (n-1) \cdot (n-2)\cdot\ldots1$$

Aaron L.

Answer:

def fact(n): if n == 0: return 1 return n * fact(n-1) This method is a prime example of recursion. Recursion is the process of repeating an operation or procedure until it is stopped by the terminal case, or "base case". In this scenario, our base case is when our given integer, n, reaches 0. When this happens, the product we have calculated through previous repetitions is multiplied by 1. We know that this base case will always be met because our integer n will always be greater than 0 and is being steadily subtracted by 1 after every iteration. Given the description of a factorial, returning the current value multiplied by that value subtracted by 1 fits perfectly. Important things to take notes of: 1. When declaring a new method, we always begin with "def", followed by the method name, and then any parameters within the following parenthesis. If there are no parameters, the parentheses are left blank. 2. Remember that the base case is a condition, which means we almost always use an if statement. We could also have added an "else" before the return statement but because there's only one condition, it would be redundant. 3. When using recursion, the self-method calling is typically done after all other operations have been programmed.

Java Programming

TutorMe

Question:

Assuming we are given two integers a and b $$(1000 > a > b > 0)$$, write a program which divides a by b. Then, print the quotient (rounded to the third decimal place) to the terminal, and return the entire result.

Aaron L.

Answer:

public double div(int a, int b){ double a1 = a; double b1 = b; double quotient = a1/b1; System.out.printf("%.3f", quotient); return quotient; } Let's discuss why this would be an optimal solution. Knowing that we are given two integers a and b, it is pertinent that our two parameters, a and b, are type "int". We must also specify that our return type will be of type double in case our quotient does not divide evenly. Accordinly we must cast our two parameters as doubles. Casting follows a specific hierarchy of data types, and because doubles are "ranked" higher than ints, we can simply create new double variables to hold these values. Now, we divide the two numbers, making sure that they are stored in a double as well to retain the decimal values. Now that we have obtained the quotient, we can format it to three decimal places using the printf method. The ".3" specifies that the variable will be formatted to 3 decimal places, and the "f" acts as a placeholder a variable of type double. We can then return the entire value using a simple "return" statement.

Calculus

TutorMe

Question:

If the galaxy can be thought of as a circular disk, we can imagine it expanding over time (while maintaining its shape) at a rate of 67 km/s. Assuming this is true, how fast is the area of this disk expanding when the radius is 100,000 light years?

Aaron L.

Answer:

In order to find the rate at which the area of the circle is expanding, we need to find the derivative of the area with respect to time. Given that the area of a circle is $$ A= \pi*r ^2 $$ where $$ r = radius $$, we find the derivative with respect to time, the equation becomes $$ \frac{dA}{dt}=2\pi*r*\frac{dr}{dt}$$. Now we can simply plug in the values for the radius and rate of expansion. $$\frac{dA}{dt}=67,000,000\pi$$ $$ly/s$$. For reference, $$\frac{dA}{dt}$$ = change in area/change in time, $$\frac{dr}{dt}$$ = change in radius/change in time.

Send a message explaining your

needs and Aaron will reply soon.

needs and Aaron will reply soon.

Contact Aaron

Ready now? Request a lesson.

Start Session

FAQs

What is a lesson?

A lesson is virtual lesson space on our platform where you and a tutor can communicate.
You'll have the option to communicate using video/audio as well as text chat.
You can also upload documents, edit papers in real time and use our cutting-edge virtual whiteboard.

How do I begin a lesson?

If the tutor is currently online, you can click the "Start Session" button above.
If they are offline, you can always send them a message to schedule a lesson.

Who are TutorMe tutors?

Many of our tutors are current college students or recent graduates of top-tier universities
like MIT, Harvard and USC.
TutorMe has thousands of top-quality tutors available to work with you.

Made in California

© 2019 TutorMe.com, Inc.