Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
edx exercise
#1
Hello guys, I'm facing some logic problems.
I barely know how to set max/min for order_weight and give order_price a variable then multiply it as well.
Please help me with this one. Thanks a lot!
These are the requirements.

set values for maximum and minimum order variables
set value for price variable
get order_amount input and cast to a number
check order_amount and give message checking against
over maximum
under minimum
else within maximum and minimum give message with calculated price
Sample input and output:

Enter cheese order weight (numeric value): 113
113.0 is more than currently available stock
Enter cheese order weight (numeric value): .15
0.15 is below minimum order amount
Enter cheese order weight (numeric value): 2
2.0 costs $15.98


number = [0.15,120]
weight_max = max(number)
weight_min = min(number)

x = 5
order_price = x * order_weight

order_weight = input("Enter order chees weight :")

if order_weight > weight_max:
    print(order_weight,"is more than currently available stock")
elif order_weight < weight_min:
    print(order_weight,"is below minimum order amount")
else:
    print("The cost is,",order_price)
Reply
#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
#3
[quote='deanhystad' pid='111395' dateline='1587489288']
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}

Thank you for all the teaching!!!
You're the kindest person that I ever met.

I've managed to do it but I didn't use dic and list. what a shame!
You did give me the inspiration tho.
really appreciate, what u said will be memorized in my mind 4ever.

max_order = 120
min_order = 0.15
 
x = order_valid = input()
order_valid = float(order_valid)


price = 3
order_price = order_valid * price

if order_valid > max_order:
    print(x,",is more than currently available stock")
elif order_valid < min_order:
    print(x,",is below minimum order amount")
else:
     print(x,"costs,","$,",order_price)
Reply


Forum Jump:

User Panel Messages

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