Write A program to input a …
CBSE, JEE, NEET, CUET
Question Bank, Mock Tests, Exam Papers
NCERT Solutions, Sample Papers, Notes, Videos
Posted by Kulamani Pradhan 4 years, 1 month ago
- 2 answers
Gaurav Seth 4 years, 1 month ago
1. Using Exponent
<textarea data-settings="" readonly="readonly" wrap="soft"></textarea>
1 2 3 |
number = int(input("enter a number: ")) sqrt = number ** 0.5 print("square root:", sqrt) |
Output:
enter a number: 64
square root: 8.0
In above program, first we’re taking a number from user as input and the entered value will be converted to int from string and will store into variable called number. Then we are using exponent (**) sign, which is used to find out the power of a number. But we know that if a number have power ½ or 0.5 then it will represent to the square root of that number. That’s why we are using 0.5 as power here. So the number**0.5 will give us square root of that number and will be stored in variable named as sqrt. In last line we’re just printing the square root of the number.
2. Using math.sqrt() Method
<textarea data-settings="" readonly="readonly" wrap="soft"></textarea>
1 2 3 4 |
import math number = int(input("enter a number:")) sqrt = math.sqrt(number) print("square root:" , sqrt) |
sqrt() is the predefined method used to find square root in python. But we have to import math module to use the sqrt() method. In first line, we’re importing math module, then in next line, taking input from user. After that we’re finding the square root of the number using sqrt() method and result will be stored into sqrt variable. In last line, just printing the square root as in first program.
3. Using math.pow() Method
<textarea data-settings="" readonly="readonly" wrap="soft"></textarea>
1 2 3 4 |
import math number = int(input("enter a number:")) sqrt = math.pow(number, 0.5) print("square root: ", sqrt) |
pow() is also a predefined method to find out power of a number, it takes two arguments as input, first is the number itself and second one is power of that number. The program is same as first program where we’re using (**) sign to find out the square root but only different is this that here we’re using a predefined method pow() instead of (**) sign to get the power of that number.
If you’ve any problem related with article or have any other possible way to find square root in python then please let us know in comments.
<center> </center>Related Questions
Posted by Hanni Pham 4 months, 1 week ago
- 0 answers
Posted by Priya Shukla 5 months, 2 weeks ago
- 1 answers
Posted by Manoj Kumar Manoj Kumar 7 months, 2 weeks ago
- 0 answers
Posted by Prawar Narang 6 months, 2 weeks ago
- 1 answers
Posted by Hanni Pham 4 months, 1 week ago
- 1 answers
Posted by Kandeepan Jothivel 6 months, 3 weeks ago
- 2 answers
Posted by Syedali Fathima 5 months, 3 weeks ago
- 1 answers
myCBSEguide
Trusted by 1 Crore+ Students
Test Generator
Create papers online. It's FREE.
CUET Mock Tests
75,000+ questions to practice only on myCBSEguide app
Yojeet Kashyap 4 years, 1 month ago
0Thank You