Square and cube of a number

EasyBasic Programs · 7 of 40

Write a Python program to print the square and cube of a given number.

Advertisement
Input
num1 = 9
Output
Square = 81
Cube = 729

Approach

  1. Use the power operator : n 2 is the square and n ** 3 is the cube.

Solution

Python
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.

More basic programs

← All 40 Basic Programs

Leave a Comment