samedi 27 février 2021

Doesn't store entered value when runs second time

I made rock,paper,scissor game. It works fine, as I wanted to, but it doesn't store entered value when runs second time, how do I fix that.

import random

tools =["Rock","Scissors","Paper"]
r="".join(tools[0])
s="".join(tools[1])
p="".join(tools[-1])
def computer_predicion():
    computer_pred = random.choice(tools)
    return computer_pred
computer=computer_predicion()
def my_predicion():
my_predicion = input("Choose (R)Rock,(S)Scissors,(P)Paper:")
    if my_predicion=="R" or my_predicion =="r":
       my_predicion = r
       return my_predicion
    elif my_predicion=="S" or my_predicion =="s":
       my_predicion = s
       return my_predicion
    elif my_predicion=="P" or my_predicion =="p":
       my_predicion = p
       return my_predicion
    else:
         print("Debils ir?")
human=my_predicion()
def game():
    message_win = ("You won!")
    message_lose = ("You lost!")
    message = "Computer:%s\nUser:%s"%(computer,human)
    if computer ==r and human==r :
       print(message+"\nIt's draw")
    elif computer == p and human == p:
       print(message + "\nIt's draw")
    elif computer == s and human == s:
       print(message + "\nIt's draw")
    elif computer == r and human==p:
       print(message+'\n'+message_win)
    elif computer == p and human==r:
       print(message+'\n'+message_lose)
    elif computer == r and human==s:
       print(message+'\n'+message_lose)
    elif computer == s and human==r:
       print(message+'\n'+message_win)
    elif computer == p and human == s:
       print(message+'\n'+message_win)
    elif computer == s and human==p:
       print(message+'\n'+message_lose)
    else:
        pass
 c=True
 while c :      //Here code runs second time if user inputs Y or y.
      game()
      h = input("Continue?(Y/N):")
      if h=="Y" or h=="y":
         my_predicion()
         computer_predicion()
         pass
      elif h=="N" or h=="n":
          c=False
      else:
           print("Wrong symbol!")

If you have any further suggestions on how to make code better I would love to hear them out. Thank you!

Aucun commentaire:

Enregistrer un commentaire