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
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
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
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
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
Top comments (0)