Computer Science, asked by Ankit69420, 1 month ago

Write a python program to input a number and print its square root, cube root, square, cube and absolute value, and also print a random number....

Answers

Answered by anindyaadhikari13
6

\texttt{\textsf{\large{\underline{Approach!}}}}

The given problem is solved using - Python.

from numpy import cbrt

from random import random

n=int(input('Enter a number: '))

print('Square root of the number:',n‎‎*‎‎*‎‎(1/2))

print('Cube root of the number:',cbrt(n))

print('Square of the number:',n‎‎*‎‎*‎‎2)

print('Cube of the number:',n‎‎*‎‎*‎‎3)

print('Absolute value of the number:',abs(n))

print('A random number: ',random())

\texttt{\textsf{\large{\underline{Explanation!}}}}

  • To print the square root of a number, we can simply raise the number to the power ½.
  • To print the cube root of a number, we can use cbrt() function present in numPy module.
  • To print square and cube of a number, we can raise the number to the power - 2 and 3.
  • abs() function is used to calculate the absolute value of a number.
  • We can generate random number using random module. The function random() generates a random number between 0 and 1.

See attachment for output. The output for random value may be different.

Attachments:
Similar questions