python - 为什么这不是用 python 打印的?

标签 python python-3.x

我尝试打印一些简单的 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 - 为什么这不是用 python 打印的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67249382/

相关文章:

python - 从原始列创建标志列集,缺失值时为 '1'

python - 突然 .py 文件无法导入模块,但仍然可以使用 CMD

Python:类型错误:无法将序列乘以 str 类型的非 int

python - 将 Combobox 的选定值绑定(bind)到子程序

python - 使用表类型的 pyodbc 没有结果

python - python中函数的均方根

python - pymongo: ImportError: 没有名为 pymongo 的模块

python - MacOS:安装了多个 python 版本且无法管理。需要清理

python - 如何解密最初使用 Fernet 加密的不同服务上的值?

python - 导入错误 : cannot import name force_text