You 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 t
Question
You 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 t
Solution
Here is a Python program that creates an inventory using a dictionary, calculates the total value of products that exceed a certain threshold, and displays the names of products whose price is less than or equal to the threshold.
# Create an inventory using a dictionary
inventory = {
'Product1': 100,
'Product2': 200,
'Product3': 300,
'Product4': 400,
'Product5': 500
}
# Set a threshold value
threshold = 250
# Initialize a variable to store the total value of products that exceed the threshold
total_value = 0
# Initialize a list to store the names of products whose price is less than or equal to the threshold
products_below_threshold = []
# Iterate over the inventory
for product, price in inventory.items():
# If the price of the product exceeds the threshold, add it to the total value
if price > threshold:
total_value += price
# If the price of the product is less than or equal to the threshold, add its name to the list
elif price <= threshold:
products_below_threshold.append(product)
# Print the total value of products that exceed the threshold
print('Total value of products that exceed the threshold:', total_value)
# Print the names of products whose price is less than or equal to the threshold
print('Products whose price is less than or equal to the threshold:', ', '.join(products_below_threshold))
This program first creates an inventory of products with their prices. It then sets a threshold value. It initializes a variable to store the total value of products that exceed the threshold and a list to store the names of products whose price is less than or equal to the threshold. It then iterates over the inventory. If the price of a product exceeds the threshold, it adds the price to the total value. If the price of a product is less than or equal to the threshold, it adds the name of the product to the list. Finally, it prints the total value of products that exceed the threshold and the names of products whose price is less than or equal to the threshold.
Similar Questions
ntory. 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
Hari is working for a retail company and has sales data in the form of a list of dictionaries, where each dictionary represents a sale with information about the productname, price, count and date. Help him to use dictionaries by writing a Python program using strings and user-defined functions to analyze sales data. The analysis should include the calculation of total sales revenue for a specific date and finding the best-selling product.Input format:First line represents the number of products, N.Subsequent lines represent productname, price, count and date.Last line represents the date for which the list of products sold on that particular date have to be fetched from the database. Output format:productname of all products which are sold on a particular date (as mentioned in the last line of input) should be displayed, one by one.Last line displays the details of the best-selling product (which is having the highest of price*count).
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),
A company has the following products in its ending inventory. Compute lower of cost or market for inventory applied separately to each product Product Quantity Cost per Unit Market per UnitProduct A 10 $ 710 $ 680Product B 15 $ 510 $ 550Product C 20 $ 660 $ 685Multiple Choice$27,950.$27,650.$1,880.$28,750.$1,915.
Objective:To work with OperatorsScenario:A new stationary shop has been opened in the city. The owner asks his accountant to take the list of items sold in the store. The list should contain the details of the items and their costs. Help the accountant to generate the prince list by writing a Python program. Generate list with just 4 products - A4sheets, pen, pencil and eraser and get the price of the items from the user. Please refer the sample input and output statements for more clarifications.Guidelines:The amount must be displayed with 2 decimal places. On entering the product price to be a negative number, the program should display the message " Invalid input" and stop the program. Sample Input 1 :Cost of A4sheet:40Cost of pen:20Cost of pencil:10Cost of eraser:5Sample Output 1 :Items DetailsA4sheet:40.00Pen:20.00Pencil:10.00Eraser:5.00Sample Input 2 :Cost of A4sheet:40Cost of pen:20Cost of pencil:10Cost of eraser:-5Sample Output 2 :Invalid inputSample Input 3 :Cost of A4sheet:86Cost of pen:10Cost of pencil:-34Sample Output 3 :Invalid input
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.