python - 该程序没有打印它是平局。我究竟做错了什么?
问题描述
当计算机的选择与玩家的选择相同时,以下程序不会打印“It's a tie”。
import random
print("welcome to rock,paper, scissors and dynamite game!")
moves=["rock","paper","scissors","dynamite"]
for i in range(1,6):
print("Round",i)
user_play=input("player "+str(i)+" choice?").lower().strip(" ")
play_moves=random.choice(moves)
computer_play=input("computer choices:"+play_moves).lower().strip(" ")
if user_play== computer_play:
print("It's a tie!")
我究竟做错了什么?
解决方案
计算机的选择存储在play_moves
变量中,因此您应该比较user_play
以play_moves
检查它是否平局:
if user_play == play_moves:
print("It's a tie!")
推荐阅读
- java - 如何从方法中提取依赖于类的上下文的变量以避免重复代码?
- groovy - Katalon:没有方法签名
- c# - 如何暂时排除属性保存到 RavenDb?
- angular - @angular/material/index.d.ts' is not a module
- sql - 如何在 SQL Server 的表中重复值?
- javascript - ExtJS 在 Grid 中为 hasMany 关联添加过滤
- scala - 在伴随对象中声明函数/方法与在特征中声明它们的优点或缺点是什么?
- python - 输入正在输入 2 if 语句
- pandas - 如何在 Pandas 中取消堆叠 Multidex 中的第一行索引
- javascript - 如何获取字符串中的特定行