python - 为什么这不在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'
,因此无论先前条件的值如何,我们都会检查条件。
推荐阅读
- javascript - 如何计算圈复杂度?
- javascript - 如何更改置顶标题的背景
- javascript - SetInterval mySQL 每秒查询一次
- python - 使用 class_weights 时无法解释决策树
- javascript - 如何通过 DOM 在 JavaScript 中获取表格标题单元格的宽度?
- uwp - 如何将 PWA 网站打包为 UWP 应用?
- android-emulator - 如何在android studio中升级chrome浏览器版本Android 7.0模拟器
- flutter - 如何在两个列子项之间居中一个小部件?
- angularjs - 递归角度指令
- javascript - Object.defineProperty 不改变元素的属性