151k views
2 votes
Write a python program to display the cube of a number upto given integer

1 Answer

2 votes

Answer:

def display_cube(n):

for i in range(1, n+1):

print("Number is : {} and cube of the number is : {}".format(i, i**3))

# Test the function

display_cube(5)

Step-by-step explanation:

This program defines a function display_cube(n) that takes an integer n as an argument and prints out the cube of the numbers from 1 to n. The range() function is used to generate a sequence of numbers from 1 to n, and the print() function is used to display the number and its cube. The ** operator is used to calculate the cube of a number. You can test the function by calling it and passing in an integer value as an argument.

User BenDes
by
7.6k points