Today's class was all about conditional statements — if, elif, and else. To make sure the concept actually sticks, sir gave us a set of practice questions to solve. Sharing them here so I can revisit them later, and maybe they'll help someone else practising the same topic!
Difficulty Level: Easy
Q1) A teacher asks five students to stand in a line. Each student wears a badge with the number 1.
Display the badge numbers from left to right.
for i in range(5):
print(1);
Q2) Five students enter the classroom one after another.
The first student gets roll number 1, the second gets 2, and so on.
Display the assigned roll numbers.
Student_roll_number=1;
for i in range(1,6):
if(Student_roll_number<=5):
print(f"student get roll number : {Student_roll_number}")
Student_roll_number+=1
Q3) A coach asks students to stand only at even-numbered positions in a queue.
Display the first five positions.
for coach in range(2,10,2):
print(coach)
print()
for i in range(1,10):
if i%2==0:
print(i)
Q4) A newly constructed building has a special lift that does not stop on every floor.
For safety reasons, it stops only at every third floor.
A person enters the lift at the ground floor and presses the "Up" button 5 times.
for floor in range(3,18,3):
print(floor);
Q5) A rocket launches with a countdown using only even numbers from 10. Display the countdown
for rocket in range(10,1,-2):
print(rocket);
Difficulty Level: Medium
Q6) In a school sports event, all students wearing ODD jersey numbers enter the ground first.
After they finish, students with EVEN jersey numbers enter. Display the order.
for print_jersey in range(1,10):
if print_jersey%2!=0:
print(print_jersey);
for print_jersey in range(1,10):
if print_jersey%2==0:
print(print_jersey)
Q7) A daughter is going on a 5-day vacation. She asks her father for ₹5 every day so she can save it.
Her father suggests a different plan. Instead of giving her ₹5 daily, he says:
Day 1: ₹1
Day 2: ₹2
Day 3: ₹3
Day 4: ₹4
Day 5: ₹5
The daughter agrees to her father's proposal.
Write a program to calculate:
A) The total amount the daughter would receive under her original plan.
B) The total amount she would receive under her father's plan.
C) Display both totals.
Redo the same activity for 10 days' leave, instead of 5 days.
total_for_gopika = 0
total_father = 0
for i in range(1, 11):
total_for_gopika+=5;
total_father+=i;
print(total_for_gopika)
print(total_father)
Q8) A king announces a unique reward for Hard Workers. On each day,
the reward is multiplied by the day's number. The reward starts at 1 gold coin.
Given the number of days n, write a program to calculate the final reward.
2 = 2 * 1
3 = 3 * 2 * 1
4 = 4 * 3 * 2 * 1
Rewards=1;
for display in range(1,6):
Rewards*=display;
print(f'Rewards for hard Workers {Rewards}')
Q9) Suppose a password consists of the letters:
A, B, C. Each letter must be used exactly once. How many different passwords are possible?
A B C
A C B
B C A
C B A
C A B
B A C
letters = "ABC"
count = 0
for first in letters:
for second in letters:
if second != first:
for third in letters:
if third != first and third != second:
print(first + second + third)
count += 1
print("Total passwords:", count)
Q10) Frog in a Well
A frog accidentally falls into a 60-foot-deep well.
Every day:
- During the day, the frog climbs 2 feet.
- During the night, it slips down 0.5 feet.
This pattern continues every day until the frog reaches the top of the well and escapes.
Write a program to determine:
- How many days it takes for the frog to get out of the well.
- On which day the frog escapes.
Note: Once the frog reaches or crosses the top of the well during the daytime,
it escapes immediately and does not slip back that night.
frog=0;
During_day=0;
while frog<60:
frog+=2;
During_day+=1
while frog>=60:
frog-=0.5
print(frog)
print(During_day)
Q11) The Saint's Flower Basket
A saint goes for a morning walk every day. During his walk,
he plucks flowers and keeps them in a basket. On his way back home, he visits 7 temples.
At each temple, he offers half of the flowers currently in his basket.
After visiting all 7 temples, he reaches home with exactly one flower remaining in his basket.
final(after)
1
Write a program to determine how many flowers the saint had in his basket before he visited the first temple.
Hint: Think carefully about whether it is easier to solve the problem from the beginning or by working backwards from the final flower.
flowers = 1
for temple in range(1,8):
flowers *= 2
print(flowers)
Q12. 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 there and proceeds to the next gate.
Write a program to determine:
- How many lashes each guard receives.
- How many Guards are there if Tenali Raman gets only one lash."""
Grards=0;
lashes=1024;
while lashes>1:
lashes//=2;
Grards+=1
print(f"total number of grards is {Grards} and they get a lashes is {lashes}");
Q13. A police officer is chasing a thief. The police officer starts at 0 meters, while the thief is 40 meters ahead. Every jump, the police officer moves 5 meters, and the thief moves 2 meters,
How many jumps does the police officer need to catch the thief ?.
police=0
thief=40;
jumpCount=0;
while police<thief:
police+=5;
thief+=2;
jumpCount+=1;
print("total jump count",jumpCount)
print(police, thief);
Top comments (0)