首页 > 解决方案 > 该程序没有打印它是平局。我究竟做错了什么?

问题描述

当计算机的选择与玩家的选择相同时,以下程序不会打印“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!")

我究竟做错了什么?

标签: python

解决方案


计算机的选择存储在play_moves变量中,因此您应该比较user_playplay_moves检查它是否平局:

if user_play == play_moves:
    print("It's a tie!")

推荐阅读