Write a program to enter the names of books and their prices as inputs in a Dictionary. Perform the following operations for the purchase of the books by the customer.· Add more details of books to the dictionary· For books priced above 1000-2999 provides a discount of 5%· For books that are priced above 3000- 5000 provide a discount of 3% on the purchase· For books above 5000 provides a discount of 2%.· Books priced below 500 no discount is provided.Input format :The input consists of the book name and price.Then the choice (1 to enter more and 0 to stop).Output format :The output prints the initial and the final dictionary based on the conditions.Refer sample input and output for the formatting specifications.Sample test cases :Input 1 :Applies Stat25001Neural Networks60000Output 1 :[('Applies Stat', 2500), ('Data science Python projects', 300), ('Handbook Statistics', 18000), ('Hands on data science', 1160), ('Machine Learning', 4000), ('Neural Networks', 6000), ('Python and R', 7215)][('Applies Stat', 2375.0), ('Data science Python projects', 300), ('Handbook Statistics', 17640.0), ('Hands on data science', 1102.0), ('Machine Learning', 3880.0), ('Neural Networks', 5880.0), ('Python and R', 7070.7)]Input 2 :Applies Stat25001Neural Networks60001Artificial Intelligence52001Computer Networks25000Output 2 :[('Applies Stat', 2500), ('Artificial Intelligence', 5200), ('Computer Networks', 2500), ('Data science Python projects', 300), ('Handbook Statistics', 18000), ('Hands on data science', 1160), ('Machine Learning', 4000), ('Neural Networks', 6000), ('Python and R', 7215)][('Applies Stat', 2375.0),
Question
Write a program to enter the names of books and their prices as inputs in a Dictionary. Perform the following operations for the purchase of the books by the customer.· Add more details of books to the dictionary· For books priced above 1000-2999 provides a discount of 5%· For books that are priced above 3000- 5000 provide a discount of 3% on the purchase· For books above 5000 provides a discount of 2%.· Books priced below 500 no discount is provided.Input format :The input consists of the book name and price.Then the choice (1 to enter more and 0 to stop).Output format :The output prints the initial and the final dictionary based on the conditions.Refer sample input and output for the formatting specifications.Sample test cases :Input 1 :Applies Stat25001Neural Networks60000Output 1 :[('Applies Stat', 2500), ('Data science Python projects', 300), ('Handbook Statistics', 18000), ('Hands on data science', 1160), ('Machine Learning', 4000), ('Neural Networks', 6000), ('Python and R', 7215)][('Applies Stat', 2375.0), ('Data science Python projects', 300), ('Handbook Statistics', 17640.0), ('Hands on data science', 1102.0), ('Machine Learning', 3880.0), ('Neural Networks', 5880.0), ('Python and R', 7070.7)]Input 2 :Applies Stat25001Neural Networks60001Artificial Intelligence52001Computer Networks25000Output 2 :[('Applies Stat', 2500), ('Artificial Intelligence', 5200), ('Computer Networks', 2500), ('Data science Python projects', 300), ('Handbook Statistics', 18000), ('Hands on data science', 1160), ('Machine Learning', 4000), ('Neural Networks', 6000), ('Python and R', 7215)][('Applies Stat', 2375.0),
Solution
Sure, here is a Python program that fulfills your requirements:
# Initialize the dictionary with some books
books = {
'Data science Python projects': 300,
'Handbook Statistics': 18000,
'Hands on data science': 1160,
'Machine Learning': 4000,
'Python and R': 7215
}
while True:
# Get book details from the user
book_name = input("Enter the book name: ")
book_price = int(input("Enter the book price: "))
# Add the book to the dictionary
books[book_name] = book_price
# Ask the user if they want to continue
choice = int(input("Enter 1 to add more books, 0 to stop: "))
if choice == 0:
break
# Apply discounts
for book, price in books.items():
if price > 5000:
books[book] = price * 0.98
elif price > 3000:
books[book] = price * 0.97
elif price > 1000:
books[book] = price * 0.95
# Print the final dictionary
print(books)
This program first initializes a dictionary with some books and their prices. It then enters a loop where it asks the user to enter the name and price of a book, and adds this book to the dictionary. The loop continues until the user enters 0.
After the loop, the program goes through all the books in the dictionary and applies a discount based on the price of the book. The final dictionary is then printed.
Similar Questions
Input 1 :2Pen0121202Book0235605Output 1 :Details of item 1 :1. Item Name: Pen2. Item No.: 123. Item Price: 1204. Discount Percent: 25. Discounted Price: 117.6Details of item 2 :1. Item Name: Book2. Item No.: 233. Item Price: 5604. Discount Percent: 55. Discounted Price: 532Total Price: 680Total Discount: 30.4
Create a structure named Book for storing book details such as title, author, edition, and price. Write a C program to input details for n books, find the highest expensive and the lowest priced books, and display their information.xxxaaaa1245yyyddd5100xxx aaaa 1 245
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
ou are tasked with managing an inventory of products in a retail store. The inventory contains various products, each with a name(key) and price(value). Use dictionary to create the inventory. Write a Python program to find the total value of products that strictly exceed a certain threshold value. Further, display the name of products whose price is less than or equal to the threshold value (Each product name should be printed in a separate line). Develop code by using user-defined function whose argument is a dictionary. DO NOT USE BUILT-IN FUNCTIONS IN CALCULATING THE RESULTS.Accept the number of products in the inventory from user, say N.Read product name and value from user for N number of products.Read threshold value from user.Print the total value of products above threshold.Sample input:
Write a C program to store the Item number, quantity sold, and Price of one item in toi.remctf file by reading values from the keyboard.Save your program as lBQ4a.cSample inputItem number quantity sold Price of oneitem(Rs)Ilo 2 12000233 6 5000320 2 10000100 5 1500b) Write a program to read the details from i.femft£ 5°/o discount is given if more than 3 itemsare purchased from an item. Display the total amount paid for each item.` Display the itemnumber and the total amount paid for each item.Save your program as lBQ4b.cSample outputItem No. Total AmountIlo233320loo24000.0028500.0020000.007125.00
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.