-3
print "Welcome to Amanda's Toy Factory"

print "At this factory, you will need to have 5 upper pieces and 2 lower pieces to create  a toy"

x = input("How many toys would you like to make?")

print "To create",x,"toys, you will need", x*5, "upper pieces and", x*2, "lower pieces"

a = input("How many upper pieces did you bring?")
b = input("How many lower pieces did you bring?")

Ex: If you input you have 23 U pieces and 5 L pieces, it should tell you that you can create 2 toys and you will have 13 U pieces and 1 L piece left.

Edit) Thank you Larry for telling me what was wrong, I corrected and submitted it.

AmandaZ
  • 3
  • 2
  • 1
    You are new so may not know this- but, it's considered bad form on SO to ask the same fundamental question in two separate questions. Instead you should edit the original question. – paisanco Sep 17 '14 at 03:14

2 Answers2

3

You're not having an Python problem, you're having an algorithm problem.

In order to figure out the maximum number of toys that can be built, you need to ask yourself "How many toys can be built from the U pieces" and "How many toys can be built from the L pieces"? The actual number of toys you can build is the lower of those two numbers, right? (Since you have to stop building toys when you run out of one or the other parts).

How do you figure how many 5-piece toys you can make out of 11, 25, or 32 pieces? You divide the number of pieces available by the pieces required for each toy.

You seem to have hit on this idea because you are dividing the pieces available by the pieces required -- but (from the name of your variables) you seem to believe this calculates the number of pieces used, not the number of toys that can be built. And you're not finding the lower of the two toy numbers.

Once you've solved for the number of toys you can build, it's easy to calculate the left-over pieces.

Larry Lustig
  • 49,320
  • 14
  • 110
  • 160
0

As Larry said, you have to review your approach to solve the problem before program the solution in any language.

After reading your last ask before this, I believe that what you expect is something like this.

toys = input('How many toys would you like to build?')

toy = {'upper': 5, 'lower': 2}

print 'To create {toys} you will need {upper} upper pieces and {lower} lower pieces'.format(toys=toys, upper=toy['upper']*toys, lower=toy['lower']*toys)

stock = {
    'upper': input('How many U Pieces did you bring?'),
    'lower': input('How many L Pieces did you bring?'),
}

complete = {
    'upper': stock['upper'] / toy['upper'],
    'lower': stock['lower'] / toy['lower'],
    }

left_parts = {
    'upper': (toys * toy['upper']) % stock['upper'],
    'lower': (toys * toy['lower']) % stock['lower'],
    }

if toys * toy['upper'] >= stock['upper'] and toys * toy['lower'] >= stock['lower']:
    print 'You can build {toys} complete toys and no pieces will left in your stock.'.format(toys=toys)
else:
    print 'You can build {toys} complete toys and {lower} lower pieces and {upper} upper pieces will left in your stock.'.format(toys=min(complete.values()), lower=left_parts['lower'], upper=left_parts['upper'])
Community
  • 1
  • 1
Mauro Baraldi
  • 6,346
  • 2
  • 32
  • 43