Page 433 - AI Ver 3.0 Class 11
P. 433

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
                        amount_to_be_paid = total_cost - discount
                        # Display the discount, amount to be paid, and the assured gift with two decimal
                        places
                        print(f"Discount: Rs {discount:.2f}")
                        print(f"Amount to be paid: Rs {amount_to_be_paid:.2f}")
                        print(f"Assured Gift: {gift}")
                     Output:

                        Enter the total cost of the items purchased (in Rs): 5168.50
                        Discount: Rs  775.27
                        Amount to be paid: Rs  4393.23
                        Assured Gift:  Electric Iron
                 6.  Write a program that calculates the sum of numbers entered by the user. The loop should continue as long as the
                     user does not enter a negative number. The loop will exit when a negative number is entered. Display the sum of
                     the entered numbers.

                        # Initialize the sum to 0
                        total_sum = 0
                        print("Enter numbers to add to the sum. Enter a negative number to stop.")
                        while True:
                            # Accept a number from the user
                            number = int(input("Enter a number: "))
                            # Check if the number is negative
                            if number < 0:
                                break  # Exit the loop if a negative number is entered
                            # Add the number to the total sum
                            total_sum += number
                        # Display the total sum
                        print("The total sum of the entered numbers is:",total_sum)
                     Output:
                        Enter numbers to add to the sum. Enter a negative number to stop.
                        Enter a number: 5
                        Enter a number: 3
                        Enter a number: 12
                        Enter a number: 23
                        Enter a number: -7
                        The total sum of the entered numbers is: 43


                                                                                          Practical Questions   431
   428   429   430   431   432   433   434   435   436   437   438