2014-10-27 61 views
0

我被卡住了,我需要在使用從getDim()獲得的寬度和長度在烏龜圖形中繪製一個箱子,並將顏色應用於getColor的箱子和箱子。我不明白如何在我的getDraw函數中調用這些函數,而不必反覆不必要地重複用戶輸入。我也需要填滿垃圾桶的底部,但是很多罐子都會與給定的長度相匹配,所以我很少使用海龜圖案,所以我迷路了。帶功能的烏龜圖形

def main(): 
    candiam = 2.5 
    height, width, length = getDim() 
    numofcans = getCans() 
    bincolor, cancolor = getColor() 
    print ("The bin dimensions are: ",height," inches high", width," inches wide and", length," inches long") 
    print ("You are recycling ",numofcans," cans.") 



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 not in range(40,61) and width not in range(40,61) 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 in range(40,61) and width in range(40,61) 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 


def drawBin(): 


main() 
+1

究竟什麼是你的問題? – jonrsharpe 2014-10-27 18:07:39

回答

0

救你回來的顏色和你回來的尺寸,並將這些放回抽獎箱... getColorgetDim兩者都明確地從用戶那裏得到輸入...這就是他們做的。 ..林不知道你所期望的,如果沒有用戶輸入

也是第二while循環中的getColor並沒有什麼不使用它

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

    if bincolor == 1: 
     bincolor = "blue" 
    elif bincolor == 2: 
     bincolor = "red" 
    elif bincolor == 3: 
     bincolor = "green" 
    elif bincolor == 4: 
     bincolor = "magenta"