Page 305 - Touhpad Ai
P. 305

13.  Write a program to accept the limit (n) from the user. Now, display the sum of all even numbers from 20 till n. Also,
                     display the even numbers.
                     # Accept the limit from the user
                     n = int(input("Enter the limit (n): "))
                     # Initialize the sum variable to 0
                     sum = 0
                     # Iterate through the range from 20 to n
                     print("Even numbers from 20 to", n, "are:")
                     for i in range(20, n + 1,2):
                             print(i, end=' ')
                             sum += i
                     print("\nThe sum of all even numbers from 20 to", n, "is:", sum)
                     Output:
                     Enter the limit (n): 43
                     Even numbers from 20 to 43 are:
                     20 22 24 26 28 30 32 34 36 38 40 42
                     The sum of all even numbers from 20 to 43 is: 372
                 14.  A cloth showroom announced the following festival discounts and assured gifts on the purchase of items, based on
                     the total cost of the items purchased:
                                 Total Cost                     Discount                      Assured Gift
                      Less than or upto ` 2000                     5%                          Wall Clock
                      ` 2001 to ` 5000                            10%                          School Bag
                      ` 5001 to ` 10000                            15%                         Electric Iron

                      More than ` 10000                           20%                         Wrist Watch
                       Write a Python code to input the total cost of the items purchased. Calculate and display the discount and amount
                     to be paid along with the assured gift.
                     # Accept the total cost from the user
                     total_cost = float(input("Enter the total cost of the items purchased (in Rs): "))
                     # Initialize discount and gift variables
                     discount = 0
                     gift = ""
                     # Determine the discount and gift based on the total cost
                     if total_cost <= 2000:
                         discount = 0.05 * total_cost
                         gift = "Wall Clock"
                     elif total_cost <= 5000:
                         discount = 0.10 * total_cost
                         gift = "School Bag"
                     elif total_cost <= 10000:
                         discount = 0.15 * total_cost
                         gift = "Electric Iron"
                     else:
                         discount = 0.20 * total_cost
                         gift = "Wrist Watch"
                     # Calculate the amount to be paid after discount


                                                                                                     Practical File  303
   300   301   302   303   304   305   306   307   308   309   310