我尝试打印一些简单的 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/