为什么这不在python中打印?

我尝试打印一些简单的 ascII 艺术,但没有一个显示出来,我做错了什么?我认为这会奏效,因为这个人首先必须输入一些东西才能继续。我想要做的就是制作一个简单的石头剪刀布游戏。如果这与它有关,我也在 python 3.9.4 上。

import random
import time
import ctypes
import os


def Main_Game():
    y = input("Enter choice: ")
    b = random.choice(choices)
    # both put same; draw
    if y == b:
        print("Game ended with a draw!")
        print("Player chose = " + y + "| Bot chose = " + b)
    # player puts rock and bot puts paper; bot wins
    elif y == "rock" and b == "paper":
        print("Bot won the match with paper!")
        print("Player chose = " + y + "| Bot chose = " + b)
    # player puts paper and bot puts rock; player wins
    elif y == "paper" and b == "rock":
        print("Player won the match with paper!")
        print("Player chose = " + y + "  |  Bot chose = " + b)
    # player puts paper and bot puts scissors; bot wins
    elif y == "paper" and b == "scissors":
        print("Bot won the match with scissors!")
        print("Player chose = " + y + "  |  Bot chose = " + b)
    # player puts scissors and bot puts paper; player wins
    elif y == "scissors" and b == "paper":
        print("Player won the match with scissors!")
        print("Player chose = " + y + "  |  Bot chose = " + b)
    # player puts rock and bot puts scissors; player wins
    elif y == "rock" and b == "scissors":
        print("Player won the match with rock!")
        print("Player chose = " + y + "  |  Bot chose = " + b)
    # player puts scissors and bot puts rock; bot wins
    elif y == "scissors" and b == "rock":
        print("Bot won the match with rock!")
        print("Player chose = " + y + "  |  Bot chose = " + b)
    elif y == 'rock':
        print("""
            _______
        ---'   ____)
              (_____)
              (_____)
              (____)
        ---.__(___)
        """)
        print("""
              #     #   #####  
              #     #  #     # 
              #     #  #       
              #     #   #####  
              #   #         # 
              # #    #     # 
              #      #####  
        """)
    elif y == 'paper':
        print("""
             _______
        ---'    ____)____
                   ______)
                  _______)
                 _______)
        ---.__________)
        """)
        print("""
              #     #   #####  
              #     #  #     # 
              #     #  #       
              #     #   #####  
              #   #         # 
              # #    #     # 
              #      #####  
        """)
    elif y == 'scissors':
        print("""
            _______
        ---'   ____)____
                  ______)
               __________)
              (____)
        ---.__(___)
        """)
        print("""
              #     #   #####  
              #     #  #     # 
              #     #  #       
              #     #   #####  
              #   #         # 
              # #    #     # 
              #      #####  
        """)
    time.sleep(3)
    clear()
    Main_Game()


clear = lambda: os.system("cls")
choices = ["rock", "paper", "scissors"]
ctypes.windll.kernel32.SetConsoleTitleW("Playing rock, paper, scissors!")
Main_Game()

回答

elif如果先前的分支全部为假,则仅检查其条件,并且您的分支处理所有可能的输入。您可能希望该elif y == 'rock'行为if y == 'rock',因此无论先前条件的值如何,我们都会检查条件。


以上是为什么这不在python中打印?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>