IF中的IF声明?

时间:2015-06-24 20:30:41

标签: python if-statement

的Python 我怎么做这个工作?它不会打印出来。

<xyz:transactionUID xmlns:xyz="http://xyz.abc.etc">

2 个答案:

答案 0 :(得分:2)

您缺少逻辑案例。你需要涵盖球员1和球员2的所有情况

if player1 == "Rock":
   if player2 == "Paper":
      print("Player 2 Wins")
   elif player2 == "Sissors":
      print("Player 1 Wins")
   elif player2 == "Rock":
      print( "Draw"):
elif player1 == "Paper":
   if player2 == "Paper":
      print("Draw")
   ...
elif player1 == "Sissors":
   if player2 == "Paper":
      print("Player 1 Wins")
   elif player2 == "Rock":
   ...

简化逻辑的另一个选择是构建预先计算结果的字典

win = "Player 1 Wins"
loose = "Player 2 Wins"
tie = "Tie"
results = { "rock": { "paper":loose, "sissors":win, "rock":tie},
            "paper": { "paper":tie, "sissors:":win, "rock":loose},
            "sissors": { "paper":win, "sissors:":tie, "rock":loose} }

使用上面的代码,你可以按照

的方式做一些事情
results["rock"]["paper"]
'Player 2 Wins'

答案 1 :(得分:0)

要完成:

if player1 == "Rock":
    if player2 == "Paper":
        print("Player 2 Wins!")
    elif player2 == "Scissors":
        print("Player 1 Wins!")
    elif player2 == "Rock":
        print("Draw")
elif player1 == "Paper":
    # Same overall format different output
elif player1 == "Scissors":
    # Same overall format different output
else:
    print("You must choose Rock, Paper, or scissors")