Python Practice Sample:
Question 1. Math Write a program that runs these steps three times:
Ask the user to enter a non-zero number (can be positive or negative).
Find the cube of the number and subtracts 100.0 from the cube.
Calculate the square root of the result above. If the result is negative, multiply the result by -1 so it is positive before calculating the square root.
Print the result with two decimal places.
CODE IN PYTHON:
number = int(input("enter a number: "))
cube=number*number*number #calculating cube
ans=cube-100 #cube-100
print("result: ",ans)
if ans<0:#if number is negative then convert it into positive
before finding square root
ans=ans*(-1)
sqrt=ans**0.5 #calculating square root
print("Square root is : ","{:.2f}".format(sqrt))
OUTPUT SNIPPET:
Hope this resolves your doubt.
Please give an upvote if you liked my solution. Thank you :)
Get Answers For Free
Most questions answered within 1 hours.