Question

126% + Zoom Add Page T Text E Format Document View Insert Table Chart Shape Media Comment Collaborate Text Challenge 3: creat126% + Zoom Add Page T Text E Format Document View Insert Table Chart Shape Media Comment Collaborate TOLMINS Text Body Updat

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Working code implemented in Python and appropriate comments provided for better understanding:

Source code for tictactoe.py:

board = [" " for i in range (9)]
def print_board():
row1 = "|{}|{}|{}|".format(board[0], board[1], board[2])
row2 = "|{}|{}|{}|".format(board[3], board[4], board[5])
row3 = "|{}|{}|{}|".format(board[6], board[7], board[8])
print()
print(row1)
print(row2)
print(row3)
print()

def player_move(icon):
if icon == "X":
number = 1
elif icon == "O":
number = 2
print("Your turn player {}".format(number))
choice = int(input("Enter you move (1-9): ").strip())
if board[choice -1] == " ":
board[choice - 1] = icon
else:
print()
print("That space is taken!")

def is_victory(icon):
if (board[0] == icon and board[1] == icon and board[2] == icon) or\
(board[3] == icon and board[4] == icon and board[5] == icon) or\
(board[6] == icon and board[7] == icon and board[8] == icon) or\
(board[0] == icon and board[3] == icon and board[6] == icon) or\
(board[1] == icon and board[4] == icon and board[7] == icon) or\
(board[2] == icon and board[5] == icon and board[8] == icon) or\
(board[0] == icon and board[4] == icon and board[8] == icon) or\
(board[2] == icon and board[4] == icon and board[6] == icon):
return True
else:
return False
  
def is_draw():
if " " not in board:
return True
else:
return False
while True:
print_board()
player_move("X")
print_board()
if is_victory("X"):
print("X Wins! Congratulations!")
break
elif is_draw():
print("Its a draw!")
break
player_move("O")
if is_victory("O"):
print_board()
print("O Wins! Congratulations!")
break
elif is_draw():
print("Its a draw!")
break

Code Screenshots:

Sample Output Screenshots:

Hope it helps, if you like the answer give it a thumbs up. Thank you.

Add a comment
Know the answer?
Add Answer to:
126% + Zoom Add Page T Text E Format Document View Insert Table Chart Shape Media...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • #2 View Zoom Add Page Insert Table Chart Text Shape Media Comment Collaborate Format Document Text Body 2) The demand f...

    #2 View Zoom Add Page Insert Table Chart Text Shape Media Comment Collaborate Format Document Text Body 2) The demand functions for a pair of commodities are given. Use partial derivatives to determine whether the commodities are substitute,complementary, or neither Style Layout More 300 100 -3000+ 40pp and2000-300p t3 Font Pi +2 Helvetica Neue Answer. Regular 11 pt 2. Complementary Character StylesNone Alignment 1.0-Single spacing y Bullets&Lists None No Bullets 0 in Indent: 0 in Bullet Text #2 View Zoom...

  • 125% Zoom THE Insert Table cul Chart T Text View Shape Media Comment Collaborate Format Document...

    125% Zoom THE Insert Table cul Chart T Text View Shape Media Comment Collaborate Format Document Text 4A Body Style Layout More Font Arial Regular 12 pt Character Styles None* Question 4 (20 points): Provide a detailed mechanism for the following transformation. Alignment HCI T oke no peroxides Spacing 10 - Single Bullets & Lists None

  • 125% Zoom T ul I Chart Text = Media Comment View Insert Table Shape Collaborate Format...

    125% Zoom T ul I Chart Text = Media Comment View Insert Table Shape Collaborate Format Document Text Body Style Layout More Font Question 5 (20 points): methylpropene Propose a synthesis of 4-methylpentanal from 2: Arial Regular 12 pt ty Character Styles None* 2-methylpropenc 4-methylpentanal Alignment T oke Spacing 10 - Single Bullets & Lists None

  • 7 #2 125 % . View Add Page Zoom Insert Table Chart Text Shape Media Comment Collaborate Format Document Text Body 2) A...

    7 #2 125 % . View Add Page Zoom Insert Table Chart Text Shape Media Comment Collaborate Format Document Text Body 2) A T-shirt shop carries two competing shirts, one endorsed by Tim Duncan and the other by LeBron James. The owner of the store can obtain both types at a cost of $3 per shirt and estimates that if Duncan shirts are sold for r dollars apiece and James shirts for y dollars apiece, consumers will buy 50- 45r45y...

  • 126% Zeam +. Add Page View Insert Table Chart Text Shape Media Comment Collaborate Format Document...

    126% Zeam +. Add Page View Insert Table Chart Text Shape Media Comment Collaborate Format Document Text 3/24/20 -3/30/20 Record Keeper: Body* Update 1. Determine the concentrations you would use in order to find the rate law for a given reaction. Style Layout More a. Here is one set of conditions fill out the rest of the table with enough sets of conditions to determine the rate law for the reaction: Font A+B >C+D Times New Roman Al mol:L [Bmol:...

  • Ev View 125%- Zoom Add Page InsertTable Chart Text Shape Media Comment Collaborate Format Document Text...

    Ev View 125%- Zoom Add Page InsertTable Chart Text Shape Media Comment Collaborate Format Document Text Body 1- a continuous random variable is uniformly distributed on interval [0,5] then the probability density function value between 0 and 5? 2-if x and y are independent random variables then the correlation between them is: 3-if random variable y is exponentially distributed with parameter gama-...... than the Style Layout More Font expected vale of Y is 2, and its standard deviation is.........: Helvetica...

  • 125% Zoom T Insert HE Table T Text = Media Comment View Chart Shape Collaborate Format...

    125% Zoom T Insert HE Table T Text = Media Comment View Chart Shape Collaborate Format Document Text C) Will the major product of free radical bromination (Bra, light) of butane be: achiral, racemic, or a single enantiomer? Body Style Layout More Font Arial Regular 12 pt Character Styles None* Alignment Question 3 (20 points): Provide structures for compounds A-E in the boxes provided below. T oke Br 2 NaNII E-3-hexene → B - Spacing 10 - Single Bullets &...

  • 125% Zoom T Insert HE Table T Text View Chart Shape Media Comment Collaborate Format Document...

    125% Zoom T Insert HE Table T Text View Chart Shape Media Comment Collaborate Format Document Text Body Question 2 (Parts A-C, 20 points): Use the energy diagrams shown below to answer parts A and B. Style Layout More Font Transition state Transition state - Products Arial ..... ............ Regular 12 pt Reactants Energy Energy Character Styles None* Reactants Products Alignment Reaction coordinate (a) Highly exothermic reaction Reaction coordinate (b) Highly endothermic reaction T oke A) Does the structure of...

  • 125% T Format Document Collaborate View Zoom Insert Table Chart Теxt Shape Media Comment Тext Question...

    125% T Format Document Collaborate View Zoom Insert Table Chart Теxt Shape Media Comment Тext Question 1 (Parts A-C, 20 points): HO, HSO A) Circle the major product of the following reaction. Body* Layout он Style More но. "он Font OH Arial 12 pt Regular B) Circle the major product of the following reaction. 1. Не(ОАе), Н,о в U 2. NaBH None Character Styles он Alignment но. OH C) Circle the major product of the following reaction Spacing 1.0 Single...

  • View Zoom Add Page Insert Table Chart Text Shape Media Comment Collaborate Format Document Text Normal...

    View Zoom Add Page Insert Table Chart Text Shape Media Comment Collaborate Format Document Text Normal (Web) 023 4 X -1600 1200 300 300 Calculate NPV@14% & IRR 300 Style More 14. An investment is expected to pay you $5000 per year for $10 years. What is this investment worth if you have an 8% required return? Font 13. If interest rates rise, what will bond prices do? What type of bonds will show the biggest s New Roman change...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT