0

I'm doing my first programming course and I'm stuck already.

I'm trying to make a program that will tell you how many toy's you can make given how many pieces the user has.

To create the toy, you need to have 5 upper pieces and 2 lower pieces.

I've assigned the upper pieces to the letter 'a' and lower pieces to the letter 'b'

This is what I currently have done

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?")

So for example, if you input you have 7 upper pieces and 5 lower pieces, it should tell you you are able to create 1 toy and that you would have 2 upper pieces left and 3 lower pieces left.

AmandaZ
  • 3
  • 2
  • always use `raw_input` not `input` – Padraic Cunningham Sep 17 '14 at 00:37
  • 2
    You write "this is what I currently have done", but none of the code you provide even attempts to solve the problem. That's not really in the spirit of showing what you've done so far. Most people here are willing to help out if you've had a good go at it and can articulate where it's going wrong, but you have to try. – Crowman Sep 17 '14 at 00:58

2 Answers2

-1
u, l = input('upper? '), input('lower? ')

nToys = min( int(u)/5, int(l)/2 )

upperLeft = u - nToys*5
lowerLeft = l - nToys*2
ssm
  • 5,277
  • 1
  • 24
  • 42
-3

okey dokey. I take it you're using an older version of python because of the way you're using print. Here's how I'd do it:

a = input()
b= input("How many lower pieces did you bring?")
upper_left_over = a % 5
lower_left_over = b % 2
upper = int(int(a)/5)
lower = int(int(b)/2)
if upper > lower:
    toys = lower
    print("You can create", str(toys), "toys")
else:
    toys = upper
    print("You can create", str(toys), "toys")
print(upper_left_over, lower_left_over)

This is obviously messy. You can clean it up. Hope this helps!

sirwhirlwind
  • 1
  • 1
  • 4