Python Rock / Paper /剪刀,带名称输入

时间:2016-01-10 16:59:39

标签: python

我正在用python创建一个石头剪刀游戏。我做的方式如下。然而,不是打印播放器1和播放器2,我想让它们成为实际名称。所以,它可以说John Wins或Joe Wins。如何实现每次打印播放器名称的raw_input。

player1 = raw_input('Enter rock/paper/scissors: ')
player2 = raw_input('Enter rock/paper/scissors: ')

if (player1 == player2):
    print "The game is a Tie"
elif (player1 == 'rock' and player2 == 'scissors'):
    print "player 1 wins"
elif (player1 == 'rock' and player2 == 'paper'):
    print "player 2 wins"
elif (player1 == 'paper' and player2 == 'rock'):
    print "player 1 wins"
elif (player1 == 'paper' and player2 == 'scissors'):
    print "player 2 wins"
elif (player1 == 'scissors' and player2 == 'paper'):
    print "player 1 wins"
elif (player1 == 'scissors' and player2 == 'rock'):
    print "player 2 wins"
else:
    print "Invalid input"

2 个答案:

答案 0 :(得分:2)

添加另外两个包含玩家名称的变量:

player1_name = raw_input('Player1 please enter your name: ')
player2_name = raw_input('Player2 please enter your name: ')

然后当你想申报胜利者时使用:

print (player1_name + 'wins')
print (player2_name + 'wins')

答案 1 :(得分:1)

first_player_name = input("Please enter your name :")
second_player_name = input("Please enter your name :")

# your code is here

print (first_player_name + " Wins!") # instead every player 1 wins
print (second_player_name + " Wins!") # instead every player 2 wins