Search code examples
randomaccessfile

Troubles Finishing First Assignment - Python


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.


Solution

  • u, l = input('upper? '), input('lower? ')
    
    nToys = min( int(u)/5, int(l)/2 )
    
    upperLeft = u - nToys*5
    lowerLeft = l - nToys*2