DEV Community

Guru prasanna
Guru prasanna

Posted on

Python Day-13 Looping-puzzles

Find whether all digits in a number are equal:

no = int(input("Enter no. "))   #333
equal = no%10 #4
while no>0:
    rem = no%10 #3
    if rem == equal:
        equal=rem
    else:
        print("All Numbers are not equal")
        break
    no//=10 #123
else:
    print("All numbers are equal")
Enter fullscreen mode Exit fullscreen mode

Output:

1)Enter no. 6666
All numbers are equal

2)Enter no. 465
All Numbers are not equal
Enter fullscreen mode Exit fullscreen mode

Puzzles:

1) Horse runs,
12steps-->To reach 1 feet
For 1 hour-->runs 1 feet
In 2nd hour-->runs 2 feet
In 3rd hour-->runs 3 feet
In 4th hour-->runs 4 feet
Total how much feet horse have covered in 4 hours

total = 0
steps = 12
ft = 1
while ft<=4:
    total = total + steps*ft
    ft = ft+1
print(total)
Enter fullscreen mode Exit fullscreen mode

Output:

120
Enter fullscreen mode Exit fullscreen mode

2)Frog fell into 30 feet well
-->It climbs 1 feet per day but at the end of the day it falls 0.5 feet down.
-->So how many days it takes to reach the top.

height = 30
up = 1
down = 0.5
total = 0
days = 0
while total<height:
    total = total + up - down
    days+=1

print(days)
Enter fullscreen mode Exit fullscreen mode

Output:

60
Enter fullscreen mode Exit fullscreen mode

3)If a Clock is delayed by 5 minutes and for every hour it delays further 5 minutes(eg.1st-->11.00,2nd-->10.55,3rd-->10.50)
-->So if a clock shows 7'O clock then at 12'O clock ,How many minutes will be delayed.

morning = 7
afternoon = 12
difference = 5
late = 0
while difference>0:
    late = late + 5
    difference-=1
print(late)
Enter fullscreen mode Exit fullscreen mode

Output:

25
Enter fullscreen mode Exit fullscreen mode

4)Convert railway time to normal time and vice versa.
eg:
Railway Time to normal time:
15:09 --> 3:09
Normal Time to Railway Time:
3:10 --> 15:10

time=float(input("Enter the time:"))
if time<=12:
    railway_time=time+12
    print("Railway time:",railway_time)

else:
    railway_time=12-time
    print("Railway time:",round(-railway_time,2))
Enter fullscreen mode Exit fullscreen mode

Output:

Enter the time:16
Railway time: 4.0

Enter the time:4
Railway time: 16.0

Enter fullscreen mode Exit fullscreen mode

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Retry later