1

input = 55555555555555555

while dividing by 10 I am getting the output as 5555555555555556.0

number = int(input())
n = number
s = 0;
m = number
while(n>=1):
    print(n)
    x=int(n)%10
    print(x)
    n=int(n)/int(10)
    print(n)
    s=s+x
print(s)

need help.

21guns
  • 23
  • 3
  • 1
    look at [`divmod` built-in function](https://docs.python.org/3/library/functions.html#divmod) and [this question](https://stackoverflow.com/questions/183853/what-is-the-difference-between-and-when-used-for-division) – Azat Ibrakov Jun 15 '19 at 06:11
  • 1
    @21guns What is the objective of your code?. Can you write the input and the expected output for your code.Thanks. – Saurav Rai Jun 15 '19 at 06:11

1 Answers1

0

You are getting a float result because the operator `/` return a float number.

In Python3, use `//` which ensures a integer return value.

Try n = n // 10.

Tinyden
  • 524
  • 4
  • 13