-2
number = 7536

print("Given number", number)

while number > 0:

    digit = number % 10        
    number = number // 10 #(what does "//" do )
    print(digit, end=" ") #(why end=" " )

Can you please explain what do last two lines do in this code exactly?

wkl
  • 77,184
  • 16
  • 165
  • 176

2 Answers2

1

The // operator performs a floor division (also called integer division). The division is performed and then rounded to the next smallest whole number

The end parameter on the print function adds a whitespace at the end of the printed value

Fran Arenas
  • 639
  • 6
  • 18
1

In number = number // 10 ,The number will be divided by 10 but the digits after the decimal point are removed(7536 / 10=753.6 but 7536 // 10=753).

The end parameter in the print function is used to add any string at the end of the output of the print statement in python. By default, the print function ends with a newline. So in print(digit, end=" ") after every digit, it would print a space instead of the new line.