Taru exam is on the head. So she started learning physics. There she learned about Pascal's law. Now she wanted to try an experiment to get a better understanding of the same.
All
1
For the experiment Taru has N buckets (numbered from 1,2,3...N) which all are initially empty. She has M number of queries. Each query represents an integer that is of 4 types.
Query 1: Fill all the buckets with water.
Query 2: Empty all even valued buckets (2, 4, 6 (N).
• Query 3: Empty all odd number buckets (1, 3, 5,
• Query 4: Empty all the buckets. (1,2,3...N).
You have to return the number of buckets that are filled after performing M queries.
N = 10 #No. of Buckets
Flag=1
while(Flag):
print("\n\nPress-1 for Query 1: Fill all the buckets with water.")
print("Press-2 for Query 2: Empty all even valued buckets (2, 4, 6 (N)")
print("Press-3 for Query 3: Empty all odd number buckets (1, 3, 5,--)");
print("Press-4 for Query 4: Empty all the buckets. (1,2,3...N)")
print("Press-0 to QUIT")
Flag = int(input("Enter Option (0 to 4): "))
if(Flag==1):
print("\nNo. of buckets filled = ",N)
if(Flag==2):
if(N%2==0):
print("\nNo. of buckets filled = ",N/2)
else:
print("\nNo. of buckets filled = ",(N+1)/2)
if(Flag==3):
if(N%2==0):
print("\nNo. of buckets filled = ",N/2)
else:
print("\nNo. of buckets filled = ",(N+1)/2)
if(Flag==4):
print("\nNo. of buckets filled = 0")
Comments
Leave a comment