Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import random
  2.  
  3. def main():
  4. options = {"r": "Rock", "p": "Paper", "s": "Scissors"}
  5. charOptions = []
  6.  
  7. for opt in options:
  8. charOptions.append(opt[0].lower())
  9.  
  10. q = ""
  11.  
  12. for i, v in enumerate(options):
  13. if(i==len(options)-1):
  14. q = q + "or ("+options[v][0]+")"+options[v][1::]+"? "
  15. else:
  16. q = q + "("+options[v][0]+")"+options[v][1::]+", "
  17.  
  18.  
  19. choice = input(q)
  20.  
  21. if(len(choice)<1):
  22. print("Unknown choice")
  23. return
  24.  
  25. char = choice[0].lower()
  26.  
  27. if(not char in charOptions):
  28. print("Unknown choice")
  29. return
  30.  
  31. cc = charOptions[random.randint(0, len(options)-1)]
  32. print("My choice: "+options[cc])
  33. print("Your choice: "+options[char])
  34.  
  35. res = beats(char, cc)
  36. result = "Tie" if res==0 else "You" if res == 1 else "Me"
  37. print("The winner is...")
  38. print(result)
  39. return
  40.  
  41. def beats(hum, cpu):
  42. if(hum==cpu):
  43. return 0
  44. if(hum=="r"):
  45. return 1 if cpu == "s" else -1
  46. if(hum=="p"):
  47. return 1 if cpu == "r" else - 1
  48. if(hum=="s"):
  49. return 1 if cpu == "p" else -1
  50. return 0
  51.  
  52. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement