Page 432 - AI_Ver_3.0_class_11
P. 432

else:
                       print("Invalid choice. Please enter 1 or 2.")
                   Output:
                     Menu:
                     1. Sum of three numbers
                     2. Product of three numbers
                     Enter your choice (1 or 2): 2
                     Enter the first number: 23
                     Enter the second number: 6
                     Enter the third number: 7
                     The product is: 966
              4.  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
              5.  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
                    430     Touchpad Artificial Intelligence (Ver. 3.0)-XI
   427   428   429   430   431   432   433   434   435   436   437