This question already has answers here:
Python Perfect Square
(3 answers)
Check if a number is a perfect square
(25 answers)
Closed 5 years ago.
I wrote this alternative to finding if a number was a perfect square or no how can I fix this:
n = input ('type n ')
message = ('false')
if n>0 and (math.sqrt(n)).is_integer(): message = ('true')
print (message)
Related
This question already has answers here:
What does the ** maths operator do in Python?
(5 answers)
Closed 5 months ago.
import math
def countSquares(x):
sqrt=x**0.5
result=int(sqrt)
return result
x=81
print(countSquares(x))
x**0.5 is "x to the power of 0.5" which essentially means square root of x.
This question already has answers here:
Python cannot handle numbers string starting with 0. Why?
(2 answers)
How do I make eval register integers such as 05 and 04 as valid?
(1 answer)
Closed 1 year ago.
Solve="30+05"
Print(eval(Solve))
#This shows leading zero error
#i want the Solve variable to be like Solve="30+5"
solve="30+05"
stripped_solve = "+".join([num.lstrip("0") for num in solve.split("+")])
print(eval(stripped_solve))
This question already has an answer here:
NumPy: Logarithm with base n
(1 answer)
Closed 2 years ago.
How can i convert the following code to log base 2?
df["col1"] = df["Target"].map(lambda i: np.log(i) if i > 0 else 0)
I think you just want to use np.log2 instead of np.log.
This question already has answers here:
How do you print superscript in Python?
(13 answers)
Closed 4 years ago.
I'm doing a maths revision program and I want to print out a question with y to the power of x(like xⁿ). I can't find a way to print it out as this form. Has anyone got any ideas?
This is how I want it to be displayed.
One possible option using ANSI escape sequences, it is not possible to control font size:
base = "x"
exponent = "n"
print('\033[1BFormula = %s\033[1A%s\033[1B etcetera'%(exponent, base))
In terminal you get:
# x
#Formula = n etcetera
This question already has answers here:
Math operations from string [duplicate]
(8 answers)
Closed 6 years ago.
I have a string with a formula 5 - 3, and I need to get the result in integer. How could I do that?
use eval function:
eval("5 - 3") # 2
test = "5-3"
print(eval(test))
Gives 2