Last active
October 24, 2017 17:29
-
-
Save joetechem/9d511d9516d2edaebc37541793d87a02 to your computer and use it in GitHub Desktop.
turtle calculator with generalization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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