DEV Community

Kuhanraja A R
Kuhanraja A R

Posted on

day - 13 at payilagam puzzles looping

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")

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)

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)

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)

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))

Output:

Enter the time:16
Railway time: 4.0

Enter the time:4
Railway time: 16.0


Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more