Python Practice › Basic Programs › Program 7
Square and cube of a number
Write a Python program to print the square and cube of a given number.
Input
num1 = 9
Output
Square = 81 Cube = 729
Approach
- Use the power operator
:n 2is the square andn ** 3is the cube.
Solution
num1 = 9 square = num1 ** 2cube = num1 ** 3print("Square =", square)print("Cube =", cube)Output
Square = 81 Cube = 729
Line by line
Lines 3-4
** raises a number to a power. num1 * num1 and num1 * num1 * num1 give the same results.
Learn the concept
New to this topic? Read the lesson, then come back.