New course! Every coder should learn Generative AI!
Try a free lesson0
9**19?
a = 9**19 == int(float(9**19)) print(int(a)) Solution: 0 9**19 = was so large I had to use a scientific calculator to find the answer. So float 9**19 would be the same but with a decimal point. They are equal, but neither is a 0, so any ideas? BTW, 9**19=1,350,851,717,672,992,089:).
4 Answers
+ 2
You are mistaken in reasoning.
float (9 ** 19) = 1, 350 851 717 672 992 e+18;
int (float (9 ** 19)) rounds to 1 350 851 717 672 992 000, which means "9 ** 19 == int (float (9 ** 19))" = "false".
a = false;
int (false) = 0;
+ 1
Thanks Vasiliy!
0
I just re-read the Python lesson on floats. It mentioned that decimal numbers would be rounded in floats. Do floats also round very large numbers as well?
0
If I understand the question correctly, then to understand fractional numbers, can rewrite it like this:
float (9 ** 19) =
= 1, 350 851 717 672 992 * (e + 18);
P.S: "Computers cannot accurately store real numbers, just as we cannot write down all the numbers after the decimal point for the 1/3 equation (0.3333333333333333 ...). Remember this, because it often leads to annoying mistakes!"