DEV Community

R.Shobika CSE
R.Shobika CSE

Posted on

PYTHON3 TASK3 day 10

TASK

  1. Tenali Raman and the Palace Guards

Tenali Raman wishes to meet the King. Before reaching the royal court, he has to pass through many palace gates. A guard is posted at each gate.

Every guard demands a share of whatever reward Tenali Raman receives from the King. Tenali Raman agrees and promises:
"I will give you half of whatever reward I receive from the King."

All the guards allow him to enter. After meeting the King, Tenali Raman receives a reward of 1024 lashes.

Keeping his promise, Tenali Raman shares his reward with the guards. At each gate, he gives half of the lashes he still has to receive to the guard at that gate and proceeds to the next gate.

Write a program to determine:

  1. How many lashes each guard receives.
  2. How many Guards are there if Tenali Raman gets only one lash

PROGRAM:

lashes=1024
gaurd=0
while lashes>1:
   lashes=lashes//2
   gaurd=gaurd+1
print(gaurd)
Enter fullscreen mode Exit fullscreen mode

output:
10

  1. Police , Thief question

PROGRAM:

police=0
thief=40
step=0
while thief>police:
  police=police+5
  thief=thief+2
  step+=1
print("police feet : ", police)
print("police step : ",step)
Enter fullscreen mode Exit fullscreen mode

police feet : 70
police step : 14

Top comments (0)