Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
turtle calculator with generalization
import turtle
def calc(number1, number2, operation, text_color, bg_color):
if operation == "+":
answer = number1 + number2
elif operation == "-":
answer = number1 - number2
elif operation == "*":
answer = number1 * number2
elif operation == "/":
answer = number1 / number2
# Setting up turtle name, creating the new window instance
frank = turtle.Turtle()
frank.pencolor(text_color)
window = turtle.Screen()
window.bgcolor(bg_color)
frank.write(answer, move=True, font = ("Arial", 100, "bold"))
turtle.mainloop()
# Call the function, pass it the arguments its waiting for.
# You can see the parameters at line three; we need an argument for each parameter
calc(int(raw_input("Give me a number: ")), # number1
int(raw_input("Give me another number: ")), # number2
raw_input("What operation? "), # operator
raw_input("Type in a color for text: "), # text_color
raw_input("type in another color for the background: ") # bg_color
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.