Single File Programming QuestionProblem StatementMeet Alex, a budget-savvy shopper who wants to give discounts to customers in the following ways:If the amount is greater than 5000 (not inclusive), the discount is 20%.If it is greater than 2000 (not inclusive), the discount is 15%.10% discount for a purchase amount greater than 1000 (not inclusive). Write a program that takes the amount as input and calculates the discounts using a function named applyDiscount. The discount rates are set as 10%, 15%, and 20% as global double datatype variables.Input format :The input consists of a double value representing the amount.Output format :The output displays "Discounted amount: " followed by a double value representing the discounted amount, rounded to two decimal places.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1000.0 ≤ Amount ≤ 10000.0Sample test cases :Input 1 :2000.0Output 1 :Discounted amount: 1800.00Input 2 :1100.50Output 2 :Discounted amount: 990.45Input 3 :10000.0Output 3 :Discounted amount: 8000.00Input 4 :1000.0Output 4 :Discounted amount: 1000.00
Question
Single File Programming QuestionProblem StatementMeet Alex, a budget-savvy shopper who wants to give discounts to customers in the following ways:If the amount is greater than 5000 (not inclusive), the discount is 20%.If it is greater than 2000 (not inclusive), the discount is 15%.10% discount for a purchase amount greater than 1000 (not inclusive). Write a program that takes the amount as input and calculates the discounts using a function named applyDiscount. The discount rates are set as 10%, 15%, and 20% as global double datatype variables.Input format :The input consists of a double value representing the amount.Output format :The output displays "Discounted amount: " followed by a double value representing the discounted amount, rounded to two decimal places.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1000.0 ≤ Amount ≤ 10000.0Sample test cases :Input 1 :2000.0Output 1 :Discounted amount: 1800.00Input 2 :1100.50Output 2 :Discounted amount: 990.45Input 3 :10000.0Output 3 :Discounted amount: 8000.00Input 4 :1000.0Output 4 :Discounted amount: 1000.00
Solution
Here is a Python solution for the problem:
# Global discount rates
discount_10 = 0.10
discount_15 = 0.15
discount_20 = 0.20
def applyDiscount(amount):
# Check the amount and apply the appropriate discount
if amount > 5000:
return round(amount * (1 - discount_20), 2)
elif amount > 2000:
return round(amount * (1 - discount_15), 2)
elif amount > 1000:
return round(amount * (1 - discount_10), 2)
else:
return amount
# Test the function
print("Discounted amount: ", applyDiscount(2000.0))
print("Discounted amount: ", applyDiscount(1100.5))
print("Discounted
Similar Questions
Single File Programming QuestionProblem StatementAmit wants to evaluate the depreciation of his car over time to understand its current value and categorize it based on that value. Write a program that helps him determine the current value of his car after a certain number of years of depreciation and classify it into one of three categories:High: If the current value is greater than 10,000.Medium: If the current value is between 5,000 and 10,000, both inclusive.Low: If the current value is less than 5,000.The depreciation rate of the car is 15% per year. The program should calculate the current value of the car after applying this depreciation over the given number of years and print the current value along with the category.Company Tags: InfosysInput format :The first line of input consists of an integer, representing the initial cost of the car.The second line consists of an integer, representing the number of years the car has been depreciating.Output format :The first line of output prints a double value, representing the current value of the car, rounded off to two decimal places.The second line prints its category.Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ initial cost ≤ 1000000 ≤ age ≤ 100Sample test cases :Input 1 :200005Output 1 :Current Value: 8874.11Category: MediumInput 2 :155377Output 2 :Current Value: 4980.81Category: LowInput 3 :125751Output 3 :Current Value: 10688.75Category: HighNote :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.
Single File Programming QuestionProblem StatementAthul, a supermarket employee, needs a program to calculate Goods and Services Tax (GST) deductions for customer purchases. The program should take a purchase code (A to F) and amount, apply the relevant GST rate, subtract it from the original amount, and print the result. The user's total amount and product code are used to calculate the GST.For example, if the amount is 100.00 and the product code is 'C', 5% GST is applied, and the amount is calculated as 100.00 - (100.00*0.05) which is equal to 95.00.Input format :The first line of the input consists of a character representing the product code ('A', 'B', 'C', 'D', 'E', or 'F').The second line consists of a float value representing the total amount.Output format :If the code is valid ('A', 'B', 'C', 'D', 'E', or 'F'), the output displays a float value representing the amount after deducting GST, rounded off to two decimal places, after applying the appropriate GST deduction.If the code is invalid, it displays "Invalid choice".Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:100.0 ≤ total amount ≤ 10000.0Sample test cases :Input 1 :C100.00Output 1 :95.00Input 2 :A2000.00Output 2 :2000.00Input 3 :W2300.67Output 3 :Invalid choiceInput 4 :B10000.00Output 4 :9800.00Input 5 :D1234.52Output 5 :1086.38Input 6 :E5678.00Output 6 :4655.96Input 7 :F9789.00Output 7 :7048.08Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.
Given an order amount, write an R script that applies a 10% discount if the order amount is more than $20. Print the final amount after discount, or the original amount if no discount is applied.
Single File Programming QuestionProblem StatementLilly went shopping with a budget of Rs. 10,000 to buy clothes, and accessories. The cost of clothes is twice the value of accessories, and there is an additional expense of Rs. 1000 for fuel. Develop an expense calculator by inputting the amount spent on accessories, then calculate and display Lilly's remaining amount rounded to two decimal places after her shopping.ExampleInput:2000.0Output:3000.0Explanation:budget = 10000.0;fuel = 1000.0;accessories = 2000.0clothes = 2 * accessories = 2 * 2000 = 4000.0total = clothes + accessories + fuel = 4000.0 + 2000.0 + 1000.0 = 7000.0remaining = budget - total = 10000.0 - 7000.0 = 3000.0Input format :The input consists of a float value a, representing the amount spent on accessories.Output format :The output prints the remaining budget after shopping, rounded to two decimal places in the following format: "Rs. [remaining amount]". Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:10.0 ≤ a ≤ 3000.0Sample test cases :Input 1 :10.0Output 1 :Rs. 8970.00Input 2 :2000.0Output 2 :Rs. 3000.00Input 3 :3000.0Output 3 :Rs. 0.00Input 4 :1578.89Output 4 :Rs. 4263.33
Ravi wants to estimate the total utility bill for a household based on the consumption of electricity, water, and gas. Write a program to calculate the total bill using the following criteria:The cost per unit for electricity is 0.12, for water is 0.05, and for gas is 0.08.A discount is applied to the total cost based on the following conditions:If the total cost is 100 or more, a 10% discount is applied.If the total cost is between 50 and 99.99, a 5% discount is applied.No discount is applied if the total cost is less than 50.The program should output the total bill after applying the discount with two decimal places.Input format :The input consists of three double values, representing the number of units consumed for electricity, water, and gas respectively.Output format :The output prints a double value, representing the total bill after applying the discount, formatted to two decimal places.Refer to the sample output for formatting specifications.Code constraints :1.00 ≤ units consumed ≤ 10000.00Sample test cases :Input 1 :1000.0200.0100.0Output 1 :124.20Input 2 :500.030.020.0Output 2 :59.95Input 3 :120.070.045.0Output 3 :21.50
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.