Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Tic Tac Toe game in python using Turtle graphics. The game will be played with user vs computer. Computer uses random to place

Create a Tic Tac Toe game in python using Turtle graphics.

The game will be played with user vs computer. Computer uses random to place 'O' in one of the untaken 9 boxes.

here's my code but you can make your own or add it to this to get it to work.

Thank you.

import turtle import random s = turtle.Screen() s = turtle.Turtle() s.speed(10) for i in range(4): s.forward(210) s.right(90) s.penup() for i in range(1): s.forward(70) s.right(90) s.pendown() s.forward(210) s.penup() for i in range(1): s.pendown() s.left(90) s.forward(70) s.left(90) s.forward(210)

s.penup() s.right(90) s.forward(70) s.right(90) s.forward(70) s.right(90) s.pendown() s.forward(210) s.penup() s.left(90) s.forward(70) s.left(90) s.pendown() s.forward(210) s.back(70) s.penup()

def draw(input,player): if input == '1': s.setposition(35,-60) s.pendown() s.write(player,align="center",font = ("Arial",25,"normal")) s.penup()

elif input == '2': s.setposition(105,-60) s.pendown() s.write(player,align="center",font = ("Arial",25,"normal")) s.penup()

elif input == '3': s.penup() s.setposition(175,-60) s.pendown() s.write(player,align="center",font = ("Arial",25,"normal"))

elif input == '4': s.penup() s.setposition(35,-120) s.pendown() s.write(player,align="center",font = ("Arial",25,"normal"))

elif input == '5': s.penup() s.setposition(105,-120) s.pendown() s.write(player,align="center",font = ("Arial",25,"normal"))

elif input == '6': s.penup() s.setposition(175,-120) s.pendown() s.write(player,align="center",font = ("Arial",25,"normal"))

elif input == '7': s.penup() s.setposition(35,-190) s.pendown() s.write(player,align="center",font = ("Arial",25,"normal"))

elif input == '8': s.penup() s.setposition(105,-190) s.pendown() s.write(player,align="center",font = ("Arial",25,"normal"))

elif input == '9': s.penup() s.setposition(175,-190) s.pendown() s.write(player,align="center",font = ("Arial",25,"normal"))

def random2(): print('1') comp = random.randint(0,9) print('2') return comp

spaces = ["","","","","","","","",""] x= 0 while x <4: print('0') comp = random2() print(comp) user= input('Enter Position: ') draw(user, 'X') draw(comp,'O') print('4') x+=1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Donald A. Carpenter Fred R. McFadden

1st Edition

8178088045, 978-8178088044

More Books

Students also viewed these Databases questions