【发布时间】:2020-05-21 23:10:34
【问题描述】:
我是 python 新手,有人告诉我一个好的起点是编写一个石头剪刀布程序。 这是我到目前为止所拥有的:
import random
term1 = "Rock"
term2 = "Paper"
term3 = "Scissors"
computerchose = [term1, term2, term3]
print("Welcome to Rock Paper Scissors!")
print("You will be versing the computer, Good luck!")
print("Rock \nPaper \nScissors")
input = input(print("please choose your weapon "))
words = input.split()
if term1 in words:
print("Oh you chose Rock did you?!? Well the computer chose {0}".format(random.choice(computerchose)))
if term2 in words:
print("Oh you chose Paper did you?!? Well the computer chose {0}".format(random.choice(computerchose)))
if term3 in words:
print("Oh you chose Scissors did you?!? Well he computer chose {0}".format(random.choice(computerchose)))
我希望尝试创造一个获胜条件。我对此的思考过程是获得 {0}.format 答案并分别检查它的 term1、term2、term3。如果有人能帮我解决这个问题,我会非常感激!
【问题讨论】:
-
你的问题是什么?
-
为什么在对
input()的调用中有print()? -
为什么需要拆分输入?您一次只能选择一种武器,包括石头、纸、剪刀。
-
请看this answer。希望您能对如何实现游戏有所了解。
标签: python python-2.7