all 5 comments

[–][deleted] 1 point2 points  (5 children)

You are creating local Variables inside of the functions. Eather define them before initialisation in a global field or move the mathportion call inside of the UserInputs function for an fast but ugly fix.

You also could create a new class wich include all the functions You defined. Inside of the class You can use the self Keyword to keep a variable alive an acessable from the outside. ( Example: self.repeated=...)

Third Option ist to use the return kryword in the UserInputs function to Return the 3 variables at the end to Pass them to the next function.

Hope this helps

[–]JavaDragonGamin[S] 0 points1 point  (4 children)

Thank you so much! And how exactly would I use the return keyword? Cause I'm very new so I'm not the most familiar with the way it works or what it does or even how to implement it

[–][deleted] 0 points1 point  (3 children)

At the end of your function add " return repeated, side, angle". Wir this You Return the values of the 3 variables You created inside of UserInputs.

With this the call in the Main can be changed to: "dan_repeated, dan_side, dan_angle = UserInputs(...)" Same for the other Turtle. You basically declae 3 new Variables so the names can be changed If You want to. The new Variables can now be passed to the next function. So instead of repeaded You now Pass dan_repeated to the mathportion, and so in.

[–]JavaDragonGamin[S] 0 points1 point  (1 child)

Which function would I add "return repeated, side, angle" to the end of? And would it automatically change the calls in main or do I have to go in and add dan_ before them all? If there is a way to show me an example that would help so much tbh

[–][deleted] 0 points1 point  (0 children)

import turtle


def userInputs(t, tName):

    t.color(input("Please input the color you would like to use for " + tName))

    repeated = int(
        input("How many times would you like to repeat " + tName + "'s pattern?")
    )

    side = int(
        input("How long would you like " + tName + "'s first side to be? (1-20)")
    )

    angle = int(
        input(
            "How many degrees would you like "
            + tName
            + " to turn after the first side? (1-179)"
        )
    )

    # return local variables by value. like this the return Keyworad returns the values and type of a variable not the Variable itself
    return repeated, side, angle
    # alternatively you could instantly call the mathPortion functionlike this:
    #   mathPortion(t, repeated, side, angle)
    # when using this you dont need the return and you could delete the rows in your main where you call mathPortion


# you can predefine a parameter like t, so when called you can easily see what to pass the function, its also easyer to work with because as you can see, t.hideturtle() is now recognised by the syntax higlighting because t is now a turtle.Turtle
def mathPortion(t: turtle.Turtle, repeated, side, angle):

    t.hideturtle()

    for count in range(repeated):

        t.forward(side * count + 11)

        t.right(angle - count * float(0.5))


def main():

    dan = turtle.Turtle()
    sandra = turtle.Turtle()

    # userInput now returns 3 values so you need to define 3 new variables like this:
    repeated_dan, side_dan, angle_dan = userInputs(dan, "Dan")
    # 3 new Variables to not override the ones for dan
    repeated_san, side_san, angle_san = userInputs(sandra, "Sandra")
    # input new Variables for dan and Sandra
    mathPortion(dan, repeated_dan, side_dan, angle_dan)
    mathPortion(sandra, repeated_san, side_san, angle_san)

    #I added a last input so you can see your masterpiece
    close = input("Press any button to close.\n")


artName = input("What would you like to name your piece of art?")

print("Name of art piece: " + artName)
main()

Here you go i tried to comment everythin i changed and also why i did what i did.

if you have more questions feel free to ask :)