Python Forum
point of sale code problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
point of sale code problem
#4
In this instance, it would be better to use a dictionary to save product.

example:
products = {
    'Iron': '24.95',
    'Home Gym': '794.95',
    'Microwave Oven': '165.00',
    'Cordless Drill': '129.95',
    'Gas Range': '495.00',
    'Washer': '399.99',
    'Stand Mixer': '159.95',
    'Dryer': '349.95',
    'Dishwasher': '595.00',
    'Treadmill': '1390.00'
 }

def get_price(product):
    return products[product]

print(f"The price of Gas range is: ${get_price('Gas Range')}")

price = get_price('Dishwasher')
print(f"Dishwasher costs: ${price}")
results:
Output:
The price of Gas range is: $495.00 Dishwasher costs: $595.00
Reply


Messages In This Thread
point of sale code problem - by dethnode - Dec-12-2022, 05:53 AM
RE: point of sale code problem - by DPaul - Dec-12-2022, 10:12 AM
RE: point of sale code problem - by popejose - Dec-12-2022, 12:48 PM
RE: point of sale code problem - by Larz60+ - Dec-13-2022, 01:55 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020