AI Assignment No2
AI Assignment No2
Turtle in Python
“Turtle” is a Python feature like a drawing board, which
lets us command a turtle to draw all over it! We can use
functions like turtle.forward(…) and turtle.right(…)
which can move the turtle around.
Q.No.01
Run this code. Python file
import turtle #Inside_Out
wn = turtle.Screen()
wn.bgcolor("light green")
skk = turtle.Turtle()
skk.color("blue")
def sqrfunc(size):
for i in range(4):
skk.fd(size)
skk.left(90)
size = size + 5
sqrfunc(6)
sqrfunc(26)
sqrfunc(46)
sqrfunc(66)
sqrfunc(86)
sqrfunc(106)
sqrfunc(126)
sqrfunc(146)
Code 2
import turtle
def calculator():
print("Select operation:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
print("5. Exit")
while True:
choice = input("Enter choice (1/2/3/4/5): ")
if choice == '5':
print("Exiting the calculator. Goodbye!")
break
if choice == '1':
print(f"The result is: {add(num1, num2)}")
elif choice == '2':
print(f"The result is: {subtract(num1, num2)}")
elif choice == '3':
print(f"The result is: {multiply(num1, num2)}")
elif choice == '4':
print(f"The result is: {divide(num1, num2)}")
else:
print("Invalid input. Please enter a number between 1 and
5.")
if __name__ == "__main__":
calculator()
output: