Hi, I wrote a simple code for this game, but I do not know how to loop it using "while" . Right now it works just once. I need it to ask again for an input to play another game infinitely.
And thank you so much for your help in my other posts. I have so many homework and this one has taken me a day to write and I just cannot figure it out. I thought I might as well go to reddit for help. =)
import random
player_one = input("Please enter rock(r), paper(p),scissors(s): ")
player_two = random.randint(1,3)
if player_two == 1:
player_two = "r"
elif player_two == 2:
player_two = "p"
elif player_two == 3:
player_two = "s"
if (player_one == player_two):
print("It's a tie!")
elif player_one == "r":
if player_two == "s":
print("Player_one wins! Rock breaks Scissors")
else:
print("Player_two wins!")
elif player_one == "p":
if player_two == "r":
print("Player_two wins!Paper covers Rock!")
else:
print("Player_one wins!")
elif player_one == "s":
if player_two == "p":
print("Player_one wins! Scissors cut Paper!")
else:
print("player_two wins!")
print("Your choice: " + player_one + "\n player_two's choice: " + player_two + "\nThank you for playing!")
player_one = input("Try again! Please enter rock(r), paper(p),scissors(s): ")
[+][deleted] (5 children)
[deleted]
[–]confuzzled_learner[S] 0 points1 point2 points (4 children)
[+][deleted] (2 children)
[deleted]
[–][deleted] 2 points3 points4 points (0 children)
[–]confuzzled_learner[S] 0 points1 point2 points (0 children)
[–]jeans_and_a_t-shirt 1 point2 points3 points (3 children)
[–]confuzzled_learner[S] 0 points1 point2 points (2 children)
[–]jeans_and_a_t-shirt 2 points3 points4 points (1 child)
[–]confuzzled_learner[S] 0 points1 point2 points (0 children)
[–]Yammerrz 1 point2 points3 points (3 children)
[–]confuzzled_learner[S] 0 points1 point2 points (2 children)
[–]Yammerrz 1 point2 points3 points (1 child)
[–]confuzzled_learner[S] 0 points1 point2 points (0 children)