@sharpvik/

Rock | Paper | Scissors

Python

No description

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.020521565360157368","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"ZnJvbSByYW5kb20gaW1wb3J0IGNob2ljZQoKY2xhc3MgUlBTOgoJZGVmIF9faW5pdF9fKHNlbGYpOgoJCXNlbGYub3B0ID0gWydyb2NrJywgJ3BhcGVyJywgJ3NjaXNzb3JzJ10KCQlzZWxmLnVzcl9zY29yZSA9IDAKCQlzZWxmLmNwdV9zY29yZSA9IDAKCQlzZWxmLnJ1bGVzID0gewoJCQkncm9jaycgCQkgIDogJ3NjaXNzb3JzJywKCQkJJ3BhcGVyJwkJICA6ICdyb2NrJywKCQkJJ3NjaXNzb3JzJwk6ICdwYXBlcicKCQl9CgkJc2VsZi5tYXRjaCgpCgoJZGVmIGVycihzZWxmLCBtc2cpOgoJCXByaW50KGYiRVJST1I6IHttc2d9IikKCglkZWYgZGlzcF9zY29yZXMoc2VsZik6CgkJcHJpbnQoZiJTQ09SRVM6XG5cdFlPVToge3NlbGYudXNyX3Njb3JlfVxuXHRDUFU6IHtzZWxmLmNwdV9zY29yZX1cbiIpCgkKCWRlZiBhc2soc2VsZik6CgkJZm9yIGkgaW4gcmFuZ2UoIGxlbihzZWxmLm9wdCkgKTogcHJpbnQoZiJ7aSArIDF9LiB7c2VsZi5vcHRbaV19IikKCQl1c3IgPSBpbnB1dCgiXG5TZWxlY3Qgb25lIG9wdGlvbjogIikKCQl0cnk6IHVzciA9IGludCh1c3IpIC0gMQoJCWV4Y2VwdCBWYWx1ZUVycm9yOiAKCQkJc2VsZi5lcnIoIklOUFVUIElOVkFMSUQhIFlPVSBNVVNUIElOUFVUIEEgTlVNQkVSIVxuIikKCQkJcmV0dXJuIHNlbGYuYXNrKCkKCQlpZiAtMSA8IHVzciA8IGxlbihzZWxmLm9wdCk6IHJldHVybiBzZWxmLm9wdFt1c3JdCgkJ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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from random import choice

class RPS:
	def __init__(self):
		self.opt = ['rock', 'paper', 'scissors']
		self.usr_score = 0
		self.cpu_score = 0
		self.rules = {
			'rock' 		  : 'scissors',
			'paper'		  : 'rock',
			'scissors'	: 'paper'
		}
		self.match()

	def err(self, msg):
		print(f"ERROR: {msg}")

	def disp_scores(self):
		print(f"SCORES:\n\tYOU: {self.usr_score}\n\tCPU: {self.cpu_score}\n")
	
	def ask(self):
		for i in range( len(self.opt) ): print(f"{i + 1}. {self.opt[i]}")
		usr = input("\nSelect one option: ")
		try: usr = int(usr) - 1
		except ValueError: 
			self.err("INPUT INVALID! YOU MUST INPUT A NUMBER!\n")
			return self.ask()
		if -1 < usr < len(self.opt): return self.opt[usr]
		else:
			self.err( "INPUT INVALID! YOU MUST INPUT A NUMBER BETWEEN 1 AND {len(self.opt)}!\n" )
			return self.ask()

	def tie(self):
		print("It's a tie")
		self.usr_score += 1
		self.cpu_score += 1

	def usr_win(self):
		print("You won!")
		self.usr_score += 1

	def cpu_win(self):
		print("CPU won!")
		self.cpu_score += 1

	def match(self):
		cpu = choice(self.opt)
		usr = self.ask()
		print(f"You chose {usr.upper()} and CPU chose {cpu.upper()}")
		if usr == cpu: self.tie()
		else:
			if self.rules[usr] == cpu: self.usr_win()
			else: self.cpu_win()
		self.disp_scores()
		endit = input("If you want to stop, enter 'q'. Otherwise, press ENTER. ").lower() == 'q'
		print()
		if not endit: self.match()
		else: print("Bye-bye!")

game = RPS()