Is it possible to type a squared number in python? Or how to type for example 5 to the power of 2
Asked
Active
Viewed 246 times
1 Answers
-1
number**power
As Joran Beasley said you only type **2 next to the number to take it to the power of 2.
In python we multiply with * so ** is multiplying two times, which is square. however *** is an error and **3 is cubic.
however you can also define a method
def power(number,n):
x=1
for n in range(n):
x=number*x
return x
print(power(5,8))
-
I was asking if there is any way of typing a square number in a string for example – Sammyng Jan 16 '22 at 11:09
-
1you can not define a int type in an str type. It is a type error. – Alberto Trujillo Sanz Jan 16 '22 at 14:13
-
2why did you flag my answer as not useful? I am not helping anyone from now on. – Alberto Trujillo Sanz Jan 16 '22 at 14:14
-
-