The next math operations that our calculator will perform are modulo raising to a power square root and logarithm. The principles are the same for writing the code for these options, meaning we're going to ask the user for one or two values, then perform the operation and finally, give him or her the option of either going back to the main menu or quitting the program. Let's start with the modulo operation. This operation corresponds to option number four in the user menu. So in this case, the upper variable should be equal to four in order to have the code under this Elif clause executed. Next, we're asking the user to enter two values and based on his or her input, we calculate the remainder of dividing the first value by the second value and printed out on the screen in a nice and readable format.
Using the print function. Lastly, using the same variable back, the user enters either Y or N to decide what to do next. So nothing new here, except for the change of the math operator, which is the percent sign in the case of the modulo operation. The same logic applies to option number five, which corresponds to the raising to a power operation. This time under this Elif statement in between the parentheses of the print function, we are using a method from within the math module called p o w. This method takes the two values provided by the user as arguments considers the first value as being the base, and the second one as being the exponent or the power. The final result is the first value raised to the power given by the second value.
The rest of the code for this Elif clause stays the same basically. Next, let's scroll down and check out the square root which corresponds to option numbers. Six. For this operation, we don't need to values but one, the user enters the number from which to extract the square root. And the code does the job of calculating the square root using the Sq RT method from within the math module. So invoking math.sq rT of well one, then converting the results to a string, and concatenating.
That string with the other strings inside the parentheses of the print function will print out the final results to the screen in an elegant way. Finally, option number seven corresponds to the logarithm to base two. To calculate this, we also need a single value being provided by the user. Since we're considering only logarithms to base two for this program. This means finding out the power to which we need to raise the number two in order to obtain the value provided by the user. For instance, if the user enters eight prompt the program, we'll find out the power that we need to raise to, to in order to get eight, which is, of course, three, because two to the power of three equals eight.
For this, we're going to use the log method from within the math module. So math dot log of Val one comma two. As you can see, the log method takes the value given by the user and also two as arguments and returns the result, the rest of the code stays the same. So I have added these four math operations to our program, each of them under its own Elif claws. And now it's time to add even more functionality to our program. So I'll see you in the next one.