I am relatively new to Python ( 3 days old ) and I was trying out a challange as per my instructor. He instructed us to prepare a game called Snake, Water and Gun ( It's basically like rock, paper, scissors ) but when I was generating a random computer choice, I was getting water everytime. Why am I getting same choice everytime and how do I fix this ? Here is the complete code.
import random
print("*****Snake Water Gun*****")
print(f"Enter the following:\n- s for Snake\n- w for Water\n- g for Gun")
hoice = ["s", "w", "g"]
cc = "Computer chose"
c = 0
u = 0
for i in range(10):
inp = input("Enter your choice : ").lower()
choice = random.choice(hoice)
if inp == "s":
if choice == "s":
print("Computer chose Snake. Draw ! ")
elif choice == "w":
u += 1
print(f"{cc} Water. You Won ! ")
else:
c += 1
print(f"{cc} Gun. Computer Won ! ")
elif inp == "w":
if choice == "s":
c += 1
print(f"{cc} Snake. Computer Won ! ")
elif choice == "w":
print(f"{cc} Water. Draw ! ")
else:
u += 1
print(f"{cc} Gun. You Won ! ")
elif inp == "g":
if choice == "s":
u += 1
print(f"{cc} Snake. You Won ! ")
elif choice == "w":
c += 1
print(f"{cc} Water. Computer Won ! ")
else:
print(f"{cc} Gun. Draw ! ")
else:
print("Please enter a valid move")
i -= 1
print(f"{u}-{c}. You won") if u > c else print(f"{u}-{c}. Computer won")
Aucun commentaire:
Enregistrer un commentaire