This question already has answers here:
Complex numbers in python
(3 answers)
Closed 4 years ago.
I want to find the absolute value of something like 'i' but when I type 'abs(1)' it says 'i' is not defined. What do I do?
In python to find the absolute value of a complex function you use j instead of i.
abs(a+bj) # General Format
abs(0+1j)
>> 1
Or you could define i as the square root of -1 and use it instead
i = (-1) ** 0.5
abs(i)
>> 1
Related
This question already has answers here:
Python and Powers Math
(3 answers)
How do I do exponentiation in python? [duplicate]
(3 answers)
Closed last year.
Is it possible to type a squared number in python?
Or how to type for example 5 to the power of 2
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))
This question already has answers here:
Calculation error with pow operator
(4 answers)
Closed 1 year ago.
Can someone explain the difference between these two expressions in Python:
(-1)**2 == 1
-1**2 == -1
Why do the parentheses change the outcome?
The parentheses means the whole value inside is will be raised to the power 2.
(-1)**2 == 1
So -1*-1 is 1
No parentheses means the - will be taken out of the equation and added to the end of the answer.
1) -1**2
2) 1**2
3) 1
4) -1
Python handles this the same way the world does :)
This question already has answers here:
Given n, take tsum of the digits of n. If that value has more than one digit, continue reducing a single-digit number is produced
(4 answers)
Closed 1 year ago.
I have problem and trying to get next:
new_string = "35" #and this result must be like new_int = 3+5.
How im available to do this? I know the type conversion, but not a clue how i should do this.
As you are new to the python, i suggest you doing it using
int(new_string[0]) # 3
int(new_string[1]) # 5
So now you have 2 integers, you can to whatever you want
This question already has answers here:
Why is exponentiation applied right to left?
(4 answers)
Closed 2 years ago.
Am New to python trying out some basic python function. Came across exponential
In python
2 ** 2 ** 3 is 256
But while in mathematics getting as 64.
Use parentheses. This will give the correct answer.
(2 ** 2) ** 3
Use parentheses
x = (2**2)**3
or:
pow(2,2*3)
This question already has answers here:
Print a float number in normal form, not exponential form / scientific notation [duplicate]
(2 answers)
How to suppress scientific notation when printing float values?
(16 answers)
Closed 2 years ago.
I want to print the whole number instead of 1e-06
number = 1
result = number/1000000
print(result)
Please help whats the best way to do it?
Try out the following by using format:
number = 1
result = number/1000000
print('{0:.6f}'.format(result))
Output:
0.000001
output = f"{num:.9f}"
you can replace 9 with the amount of numbers you have after the decimal point in your number.
and also you will need to define your variable to float to order it will work.