You are on page 1of 9

Lab Assignment BA104

30-1-2024

Q1) Consider a scenario where a child eats five chocolates every day of week.
The price of each chocolate is different. His father pays the bill to the vendor at
the end of every week. Write a script that can generate the bill of the chocolates
after a week.
ANS days_of_week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
'Saturday', 'Sunday']
chocolate_prices = [1.5, 2.0, 1.8, 1.2, 2.5, 1.0, 1.5]
total_bill = 0

for day in days_of_week:


chocolates_consumed_per_day = 5
price_per_chocolate = chocolate_prices[days_of_week.index(day)]
daily_bill = chocolates_consumed_per_day * price_per_chocolate
total_bill += daily_bill
print(f"On {day}, {chocolates_consumed_per_day} chocolates were
consumed, costing ${daily_bill}")
print(f"\nTotal bill for the week: ${total_bill}")
Q2) WAP to print following patterns (use nested loops):
(i)

(ii)
(iii)

(iv)

(v)
(iii) WAP to generate the following output (hint: use continue statement where
ever necessary)

i) for i in range(1, 7):

for j in range(1, i + 1):

print(j, end="")

print()
ii) for i in range(1, 6):

for j in range(1, i + 1):

print(i, end="")

print()
iii) for i in range(6):

for j in range(i + 1):

print("*", end=" ")

print()
iv) for i in range(6, 0, -1):

for j in range(6, i-1, -1):

print(j, end="")

print()
v) for i in range(1, 6):

for j in range(1, 6):

print(i * j, end=" ")

print()
iii) for i in range(1, 11):

result = 3 * i

print(f"3 X {i} = {result}")

for i in range(1, 11):


result = 2 * i
print(f"2 X {i} = {result}")

You might also like