From the course: Learning the Python 3 Standard Library
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Factorial, square root, and GCD - Python Tutorial
From the course: Learning the Python 3 Standard Library
Factorial, square root, and GCD
- [Instructor] Let's dive deeper into the math module. First, we have to import math because we have to have our module we're working with. And we are going to start off by looking at the factorial function. To use it, you just do math.factorial, and it'll get the factorial of any number you want. And so to start off, we'll go 3, and then we'll go ahead and print this whole thing out. And so this will just give us the factorial of 3, and that would be 3 times 2 times 1, which will give us 6 in the output. Another function that's just built into the math module, ready for us to use is square root. We'll go print math. the square root, and so sqrt, and then any number you want to get the square root of. Here, we'll just do 64. And the square root of 64 is 8, and that's what we get in the output. Another thing Python can do is help us find the greatest common denominator between two numbers. The name of the method we use…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Trigonometry, ceiling, floor, and constants4m 23s
-
(Locked)
Factorial, square root, and GCD4m 2s
-
(Locked)
Python random module6m
-
(Locked)
Calculating statistics with Python4m 41s
-
(Locked)
Iterators with itertools: Infinite processes4m 20s
-
(Locked)
Iterators with itertools: Permutations and combinations4m 26s
-
(Locked)
Solution: Calculate hypotenuse59s
-
-
-
-