Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 123 - 2611_SmartGPT Pro V(5.0) C-7
P. 123

    Show the final amount of discount and amount to be paid.

                         Program17.py
                      File  Edit  Format   Run    Options   Window    Help

                      amount = float(input("Enter the total purchase amount: "))

                      if amount >= 5000:
                          discount = 0.20  # 20% discount
                          print("You get a 20% discount.")

                      elif amount >= 3000:
                          discount = 0.10  # 10% discount

                          print("You get a 10% discount.")
                      elif amount >= 1000:
                          discount = 0.05  # 5% discount

                          print("You get a 5% discount.")
                      else:
                          discount = 0     # No discount

                          print("No discount available.")
                      discount_amount=amount*discount

                      print("Discount amount is : ", discount_amount)
                      final_amount = amount - (amount * discount)
                      print("Amount to be paid after discount:", final_amount)

                         Output

                      Enter the total purchase amount: 2500
                      You get a 5% discount.
                      Discount amount is: 125.0

                      Amount to be paid after discount: 2375.0

                     Program 18. To print a right-angled triangle using the pattern of stars.
                     *

                     **

                     ***
                     ****

                     *****

                                                                                               Flow of Control in Python  121

| 118 119 120 121 122 123 124 125 126 127 128 |