DEV Community

bhuvaneswari nandhagopal
bhuvaneswari nandhagopal

Posted on

While Loop Number Programs in python:

task -1:

no = 1234   
while no >0:
    if no >=10:
     print(no % 100)
    no = no//10
Enter fullscreen mode Exit fullscreen mode

output
34
23
12

task-2:

no = 1234
while no >=10:
   print(no % 100)
   no = no//100
Enter fullscreen mode Exit fullscreen mode

output:
34
12

task -3:(Addition of task-1)

no = 1234
total = 0
while no >= 10:
   total = total + (no % 100)
   no = no // 10

print("total:",total)
Enter fullscreen mode Exit fullscreen mode

output
69

task-4:(Addition of task-2)

no = 1234
total = 0

while no >= 10:
    total = total + (no % 100)
    no = no // 100

print("total:", total)
Enter fullscreen mode Exit fullscreen mode

output
46

task-5:(given numbers 123456---> output 456 123)

no = 123456

while no > 0:
    print(no % 1000)
    no = no // 1000
Enter fullscreen mode Exit fullscreen mode

output
456
123

Top comments (0)