MacaroniChez
New Coder
In python, I made a very decent calculator that has addition, subtraction, multiplication, and division. Today, I decided that I'm gonna expand on it and add square roots. The first thing I did was Google for how to use square roots on python. It told me that I have to import in math. After that, I was able to use sqrt to add square roots. The first problem I faced with making this was that I had two variables called number1 and number2. I needed to find a way to get rid of number2, you I used code like this:
[CODE lang="python" title="Square root"]import math
operation = input("Which operation do you want to use?")
number1 = int(input("Choose a number."))
number2 = int(input("Choose another number."))
if operation == "square root":
del number1
math.sqrt(number1)
if operation == "+":
print(number1 + number2)
if operation == "-":
print(number1 - number2)
if operation == "*":
print(number1 * number2)
if operation == "/"
print(number1 // number2)][/CODE]
I didn't get an error doing this, but it square root function did not work at all. I tried doing other things, and they all resulted in error. If you know in any way how you can add square roots to this calculator, can you please let me know? Thanks!
[CODE lang="python" title="Square root"]import math
operation = input("Which operation do you want to use?")
number1 = int(input("Choose a number."))
number2 = int(input("Choose another number."))
if operation == "square root":
del number1
math.sqrt(number1)
if operation == "+":
print(number1 + number2)
if operation == "-":
print(number1 - number2)
if operation == "*":
print(number1 * number2)
if operation == "/"
print(number1 // number2)][/CODE]
I didn't get an error doing this, but it square root function did not work at all. I tried doing other things, and they all resulted in error. If you know in any way how you can add square roots to this calculator, can you please let me know? Thanks!
Last edited by a moderator: