Skip to content

Instantly share code, notes, and snippets.

@joetechem
Last active October 24, 2017 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joetechem/9d511d9516d2edaebc37541793d87a02 to your computer and use it in GitHub Desktop.
Save joetechem/9d511d9516d2edaebc37541793d87a02 to your computer and use it in GitHub Desktop.
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