Problem 1:
A daughter is going on a 5-day vacation. She asks her father to give her Rs. 5 every day, so she can save the money.
Her father suggests a different plan. Instead of giving her Rs. 5 daily, he says:
Day 1: Rs. 1
Day 2: Rs. 2
Day 3: Rs. 3
Day 4: Rs. 4
Day 5: Rs. 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.
box = 0
day = 1
box = box + 5
day = 2
box = box + 5
day = 3
box = box + 5
day = 4
box = box + 5
day = 5
box = box + 5
print(box)
box = 0
day = 1
box = box + 5
day = day + 1
box = box + 5
day = day + 1
box = box + 5
day = day + 1
box = box + 5
day = day + 1
box = box + 5
print(box)
box = 0
day = 1
while day <= 5:
box = box + 5
day = day + 1
print(box)
box = 0
day = 1
box = box + 1
day = 2
box = box + 2
day = 3
box = box + 3
day = 4
box = box + 4
day = 5
box = box + 5
print(box)
box = 0
day = 1
box = box + day
day = day + 1
box = box + day
day = day + 1
box = box + day
day = day + 1
box = box + day
day = day + 1
box = box + day
print(box)
python
box = 0
day = 1
while day <=5:
box = box + day
day = day + 1
print(box)
-----------------
total = 0
no = 1
while no <= 10:
total = total + no
no = no + 1
print(total)
*Multiplication of First n Numbers: *
total = 1
no = 1
while no <= 10:
total = total * no
no = no + 1
print(total)
*Addition of First n numbers: *
1 * 2 * 3 * 4 * 5
Additive Identity: 0
Multiplicative Identity: 1
2.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.
- 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.
total_depth = 60
day = 0
while total_depth >= 2:
total_depth = total_depth - 2 #58
total_depth = total_depth + 0.5 #58.5
day = day + 1
print(day)
Problem : 3
3.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.
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.
count = 1
temples_visited = 7
count = count * 2 #2
temples_visited = temples_visited - 1
count = count * 2 #4
temples_visited = temples_visited - 1
count = count * 2 #8
temples_visited = temples_visited - 1
count = count * 2 #16
temples_visited = temples_visited - 1
count = count * 2 #32
temples_visited = temples_visited - 1
count = count * 2 #64
temples_visited = temples_visited - 1
count = count * 2 #128
count = 1
temples_visited = 7
while temples_visited > 0:
count = count * 2 #2
temples_visited = temples_visited - 1
print(count)
Top comments (0)