0

I have this program, I want to use these functions to ask for the height, width, and length and have them as separate variables so I can use them to draw in turtle graphics. Also with my getColor function I want to return the bin and can colors seperately so I can apply them in turtle graphics. I am kind of confused on parameters; would they be useful here?

def main():

    print ("The bin dimensions are: ",(getDim()))
    numofcans = getCans()
    print ("You are recycling ",numofcans,"cans.")
    print("Your bin color is ",getColor())


def getDim():

    height = int(input("Enter the bins height (40 to 60): "))
    width = int(input("Enter the bins width (40 to 60): "))
    length = int(input("Enter the bins length (40 to 60): "))
    while height and width and length not in range(40,61):
        print("You entered a wrong value")
        height = int(input("Enter the height (40 to 60: "))
        width = int(input("Enter the width(40 to 60: "))
        length = int(input("Enter the length (40 to 60: "))
    if height and width and length in range(40,61):
        return height, width, length

def getCans():

    cans = int(input("Enter the amount of cans (10,1000): "))
    if cans in range(10,1001):
        return cans
    while cans not in range(10,1001):
        cans = int(input("Invalid number, please enter the amount of cans (10,1000): "))
        return cans

def getColor():
    bincolor = int(input("Color menu \n 1 = 'blue' \n 2 = 'red' \n 3 = 'green' \n 4 = 'magenta' \nPick the bin color: "))
    while bincolor not in range(1,5):
        bincolor = int(input("Color menu \n 1 = 'blue' \n 2 = 'red' \n 3 = 'green' \n 4 = 'magenta' \nPick the bin color: "))
    while bincolor in range(1,5):
        if bincolor == 1:
            bincolor = "blue"
        elif bincolor == 2:
            bincolor = "red"
        elif bincolor == 3:
            bincolor = "green"
        elif bincolor == 4:
            bincolor = "magenta"


    cancolor = int(input("Color menu \n 1 = 'blue' \n 2 = 'red' \n 3 = 'green' \n 4 = 'magenta' \nPick the can color: "))
    while cancolor not in range(1,5):
        cancolor = int(input("Color menu \n 1 = 'blue' \n 2 = 'red' \n 3 = 'green' \n 4 = 'magenta' \nPick the can color: "))

    while cancolor in range(1,5):
        if cancolor == 1:
            cancolor = "blue"
        elif cancolor == 2:
            cancolor = "red"
        elif cancolor == 3:
            cancolor = "green"
        elif cancolor == 4:
            cancolor = "magenta"
        return bincolor, cancolor






main()

traceback:

>>> 
Enter the bins height (40 to 60): 45
Enter the bins width (40 to 60): 46
Enter the bins length (40 to 60): 47
The bin dimensions are:  (45, 46, 47)
Enter the amount of cans (10,1000): 101
You are recycling  101 cans.
Color menu 
 1 = 'blue' 
 2 = 'red' 
 3 = 'green' 
 4 = 'magenta' 
Pick the bin color: 1
Color menu 
 1 = 'blue' 
 2 = 'red' 
 3 = 'green' 
 4 = 'magenta' 
Pick the can color: 3
Your bin color is  ('blue', 'green')
>>> 
  • If you're trying to check if `height in range(40,61) and width in range(40,61) and length in range(40,61)`, that code isn't doing it; your if statements are essentially checking if height, and if width, and if length in range(40,61) -- essentially what you probably want for length, but for h and w it's just checking to see if their values are 'truthy'. – a p Oct 27 '14 at 16:50

2 Answers2

0

something like

colors = getColor()

first = colors[0]
second = colors[1]

should do the trick

hope I was not mistaken, no python on hand now.

See also : How do you return multiple values in Python?

Community
  • 1
  • 1
Lioobayoyo
  • 156
  • 1
  • 7
0

You're already return as tuples, so you can simply call your functions and unpack them into new variables instead of printing them:

def main():
    height, width, length = getDim()
    numofcans = getCans()
    bincolor, cancolor = getColor()
    # go on to do rest of program
    ...
flakes
  • 21,558
  • 8
  • 41
  • 88
  • This helped alot, does anyone know how I could use turtle graphics to draw the bottom of the bin with turtle graphics with the getDim function? – john diggle Oct 27 '14 at 17:23
  • @john diggle I'm not sure, I've never used turtle. You're best off asking this in a new SO question (SO questions should focus on one idea only). Also try your best to solve it yourself using this answer, and then post what you've tried in your new question! – flakes Oct 27 '14 at 17:28