Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
edx exercise
#2
Yeah, you do have a logic error.

The first thing you need to do is stop thinking about writing a program and start thinking about how you would solve this problem without a computer.

Requirements:
1. Set values for maximum and minimum order variables
Your order system has limits on how many or how few items can be ordered. It's not as common as it once was, but I still run across "Minimum order qty 12". You also have a max order qty. This is really popular in those commercials on TV where you are getting a "special price if you call in the next 6 minutes" and are limited to quantity 6 when nobody in their right mind would want more than 1.

You will need a min_order, and a max_order for each type of item in your inventory/catalog.

2. Set value for price variable

This one is pretty easy to understand. Each item you sell has a sales price.

3. Get order_amount input and cast to a number

Hope this is self explanatory

4. Check order_amount and give message checking against
over maximum
under minimum

We want to check if the customer is ordering too few or too many of an item. We can only process an order if the quantity is >= minimum order and <= maximum order.


5. Within maximum and minimum give message with calculated price

If the quantity test (requirement 4) passes, process the order. In this case processing the order mans printing a message that include the price. Would probably be nice to reference what was ordered and how many as well, but this is not mentioned in the requirements.

You may want to thing about how you will organize your information. This is just plain wrong:
number = [0.15,120] # Huh?
weight_max = max(number)
weight_min = min(number)
x = 5 # What is x?
but this, though correct, will only work for 1 item.
weight_max = 120 # Weight of what?
weight_min = 0.15
price = 5  # Price of what?
You could make it work for more than one item by being more specific:
cheese_weight_max = 120  #Ahh.  Now I know
cheese_weight_min = 0.15
cheese_price=5
But if you have hundreds or thousands of items this becomes impossible to use.

Designing for the future (I know you don't care, but I helped you so listen to the rant)
There are data structures in python that allow organizing information in a way that makes it easier to retrieve. For example, we could save all the information for cheese in a dictionary:

cheese = {'price': 5, 'min order': 0.15, 'max order': 120}

Then I could test if my order is valid.
order_valid = qty >= cheese['min order'] and qty <= cheese['max order']
order_prices = qty * cheese['price']
In python you can have dictionaries that contain dictionaries, so you could have a dictionary that contains your entire inventory, each entry being a dictionary containing information about a particular item.
inventory = {}
inventory['cheese'] = {'price': 5, 'min order': 0.15, 'max order': 120}
inventory['milk'] = {'price': 1, 'min order': 0.25, 'max order': 10}
Can you see how this would allow scaling up your order processing program to eventually become Amazon? Lookout Bezos
Reply


Messages In This Thread
edx exercise - by timthebouncer - Apr-21-2020, 12:58 PM
RE: edx exercise - by deanhystad - Apr-21-2020, 05:14 PM
RE: edx exercise - by timthebouncer - Apr-22-2020, 01:52 PM

Forum Jump:

User Panel Messages

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