简体   繁体   English

带功能的海龟图形

[英]turtle graphics with functions

I am stuck, I need to draw a bin in turtle graphics using the width and length I get from getDim() , and apply the color to the can and bin from getColor . 我被困住了,我需要使用从getDim()获得的宽度和长度在乌龟图形中绘制一个容器,然后将颜色应用于getColor的罐和容器。 I don't understand how to call those functions in my getDraw function without having the user input repeatedly unnecessarily. 我不理解如何在没有让用户不必要地重复输入的情况下在getDraw函数中调用这些函数。 I also need to fill up the bottom row of the bin with however many cans will fit with the given length, I rarely use turtle graphics so I am lost. 我还需要用给定的长度装满许多罐子来填充垃圾箱的底行,我很少使用乌龟图形,所以迷路了。

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()

save the color you get back and the dimensions you get back and pass those back into draw bin ... getColor and getDim both are explicitly to get input from the user... that is all they do ... Im not sure what you would expect if not user input 保存您返回的颜色和返回的尺寸,然后将其传递回绘图getDim ... getColorgetDim都明确地从用户那里获取输入信息...这就是他们所做的...我不确定您要做什么如果没有用户输入会期望

also the second while loop in getColor does nothing dont use it 而且getColor中的第二个while循环什么也不用

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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM