Page 41 - ipp11
P. 41
my_list = new_list
print("Duplicates removed successfully!")
elif choice == 6:
try:
num_list = list(map(int, my_list))
print("Maximum:", max(num_list), "Minimum:", Minimum, min(num_list))
except ValueError:
print("List contains non-numeric values, unable to find max/min.")
elif choice == 7:
print("Current List:", my_list)
elif choice == 8:
print("Exiting the program.")
break
else:
print("Invalid choice, please try again.")
OR
(b) inventory = {}
while True:
print("\nMenu:")
print("1. Add a New Product")
print("2. Update Product Stock")
print("3. Sell a Product")
print("4. Display Sorted Inventory Records")
print("5. Remove a Product from Inventory")
print("6. Exit")
choice = int(input("Enter your choice (1-6): "))
if choice == 1:
product_id = input("Enter Product ID: ")
name = input("Enter Product Name: ")
stock = int(input("Enter Stock Quantity: "))
price = float(input("Enter Price per Unit: "))
inventory[product_id] = {"Name": name, "Stock": stock, "Price": price}
print("Name", name, "added successfully!")
elif choice == 2:
product_id = input("Enter Product ID to update stock: ")
if product_id in inventory:
new_stock = int(input("Enter new stock quantity: "))
inventory[product_id]["Stock"] += new_stock
print("Stock updated successfully!")
else:
print("Product not found!")
elif choice == 3:
product_id = input("Enter Product ID to sell: ")
if product_id in inventory:
quantity = int(input("Enter quantity to sell: "))
if inventory[product_id]["Stock"] >= quantity:
inventory[product_id]["Stock"] -= quantity
print("Sold", quantity , "units of", inventory[product_id]['Name'])
else:
print("Insufficient stock!")
M.11