如何使特定的if语句(在嵌套的ifs中)起作用?

时间:2019-01-22 01:42:05

标签: python

我正在尝试制作一个基于文本的井字游戏,该游戏主要由嵌套的if组成。但是我的第三个if语句没有执行应有的功能。

我不知道该怎么办,因为我是一个完整的初学者,我很困惑。

print("Welcome to the text-based Tic Tac Toe!")
print("  1| 2 |3 ")
print(" ---------")
print("  4| 5 |6 ")
print(" ---------")
print("  7| 8 |9 ")`enter code here`
print("You can choose where you want to place your letter")
print("By choosing the number of that spot or place in the grid")
choice=input("What do you want to be(X/O)?: ")
while(choice=="X"):
    plychoice=int(input("Where would you like to place your letter? "))
    if plychoice==1:*#This is if the player chooses to place their letter in the "1" slot*
     print("  X|   |  ")
     print(" ---------")
     print("   | O |  ")
     print(" ---------enter code here")
     print("   |   |  ")
     plychoice=int(input("Where would you like to place your letter? "))
     if plychoice==9:#This is if the player chooses to place their letter in the "9" slot
         print("  X|   |O ")
         print(" ---------")
         print("   | O |  ")
         print(" ---------")
         print("   |   |X ")
         plychoice==int(input("Where would you like to place your letter? "))
         if plychoice==7:#This is if the player chooses to place their letter in the "7" slot
           print("  X|   |O ")
           print(" ---------")
           print("  O| O |  ")
           print(" ---------")
           print("  X|   |X ")
           plychoice==int(input("Where would you like to place your letter? "))
           if plychoice==8:#This is if the player chooses to place their letter in the "8" slot
               print("  X|   |O ")
               print(" ---------")
               print("  O| O |  ")
               print(" ---------")
               print("  X| X |X ")
               print("YOU WON!!!")

我希望第三个嵌套的if语句执行其代码。

0 个答案:

没有答案