Title: count 0 crash
Type: Stage: resolved
Components: Build Versions: Python 3.8
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, remi.lapeyre, talha.demirsoy
Priority: normal Keywords:

Created on 2020-04-05 22:44 by talha.demirsoy, last changed 2020-04-05 23:19 by BTaskaya. This issue is now closed.

File name Uploaded Description Edit talha.demirsoy, 2020-04-05 22:44
Messages (5)
msg365827 - (view) Author: Talha Demirsoy (talha.demirsoy) Date: 2020-04-05 22:44
Dear Python Developers,

I made a program that finds how many 0's at the end of the number

But when I enter number has 23 zero its okay but when I enter number has 24 zero its crash
msg365828 - (view) Author: Furkan Onder (furkanonder) * Date: 2020-04-05 23:06
Can i see the program code?
msg365829 - (view) Author: Talha Demirsoy (talha.demirsoy) Date: 2020-04-05 23:07
I shared but I write again.

sayac = 0
fakto = 10000000000000000000000
while True:
    if fakto % 10 == 0:
        sayac += 1
        fakto = fakto / 10
    elif fakto % 10 > 0:
msg365830 - (view) Author: RĂ©mi Lapeyre (remi.lapeyre) * Date: 2020-04-05 23:13
Hi Talha, you are using floating points division which convert its operands to floats so it loose precision for large numbers. The syntax for integer division in Python 3 is // and it will not change the type of its operands. Notice the difference below:

>>> 100000000000000000000000000/10 % 10
>>> 100000000000000000000000000.0//10 % 10
>>> 100000000000000000000000000//10 % 10

As you can see, in the first example the operand got changed to float which caused a loss of precision and we get the same result when we try directly with a float. Using // gives the expected result.

Python use perfect arithmetic for integers but IEEE 754 for floating point calculations. You will find that there is a lot of those "quirks" when using either very large or very small numbers and will need to be mindful of them.

In the program you linked, changing '/' to '//' should gives the result you are expecting.
msg365831 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2020-04-05 23:19
Closing issue since it is not a bug, at least a bug of python itself. Feel free to post any questions to python-list mailing list.
Date User Action Args
2020-04-05 23:19:35BTaskayasetstatus: open -> closed

type: crash ->

nosy: + BTaskaya
messages: + msg365831
resolution: not a bug
stage: resolved
2020-04-05 23:13:04remi.lapeyresetnosy: + remi.lapeyre, - furkanonder
messages: + msg365830
2020-04-05 23:07:42talha.demirsoysetmessages: + msg365829
2020-04-05 23:06:23furkanondersetnosy: + furkanonder
messages: + msg365828
2020-04-05 22:44:37talha.demirsoycreate