+ 1

How is the output 4.0?

print(abs(4j)) print(abs(4a)) print(abs(4b)) output: 4.0 SyntaxError SyntaxError

29th Oct 2022, 8:32 AM
Shantanu
Shantanu - avatar
4 Respuestas
+ 5
4j is a notation of a complex number with 0 as real and 4 as imaginary part. Absolute value of a complex number is its distance from the Origin (center) on the complex plane. https://www.varsitytutors.com/hotmath/hotmath_help/topics/absolute-value-complex-number
29th Oct 2022, 8:51 AM
Tibor Santa
Tibor Santa - avatar
+ 6
In Python, 4j is a complex number. The full representation would be 0+4j, where the real part is 0 and the imaginary part 4j. As indicated, 4a and 4b are just syntax errors. To find the absolute value of that imaginary number, find the absolute length of the line between the points on the real and imaginary axes. The Pythagorean theorem is used: sqrt(0*0 + 4*4) = 4.0
29th Oct 2022, 8:51 AM
Brian
Brian - avatar
+ 5
Python has support for complex data types.. Its of the form (a +bj) So first one is valid complex number . But later 2 are invalid identfiers.. edit: https://www.pythonforbeginners.com/data-types/complex-numbers-in-python
29th Oct 2022, 8:52 AM
Jayakrishna 🇮🇳