python - Why does this rock-paper-scissors almost always returns "tie(draw)"? -
this program returns "it's draw(or tie)". me or wrong? rock paper scissors program 10 rounds , shows results in end.
#!/usr/bin/python # rockpaperscissors python import random; = 1; c = 0; u = 0; d = 0; while <= 10: useranswer = input("do choose rock, paper, or scissors?"); computeranswer = random.randint(1, 3); if (computeranswer == 1): computeranswer = "rock"; elif (computeranswer == 2): computeranswer = "paper"; else: computeranswer = "scissors"; if (computeranswer == "rock" , useranswer == "paper"): print("you won(paper beats rock)"); u = u + 1; elif (computeranswer == "" , useranswer == "paper"): print("you lost(rock beats scissors)"); c = c + 1; elif (computeranswer == "paper" , useranswer == "rock"): print("you lost(paper beats rock)"); c = c + 1; elif (computeranswer == "paper" , useranswer == "scissors"): print ("you won(scissors beat paper)"); u = u + 1; elif (computeranswer == "scissors" , useranswer == "paper"): print("you lost(scissors beats paper)"); c = c + 1; elif (computeranswer == "scissors" , useranswer == "rock"): print("you won(rock beats scissors)"); u = u + 1; else: print("it's draw!"); d = d + 1; if (i == 10): print("you won " + str(u) + " times."); print("you lost " + str(c) + " times.") print("it draw " + str(d) + " times."); += 1;
the version of python 3.2(python 3.2)
one of test cases has couple of errors.
elif (computeranswer == "" , useranswer == "paper"): print("you lost(rock beats scissors)"); c = c + 1;
fix computeranswer == ""
computer's answer rock instead of nothing , make user's answer scissors instead of paper.
Comments
Post a Comment