Commits

Yeuk Hon Wong  committed de75e78 Draft

Moved prs stuff into solutions.

  • Participants
  • Parent commits 56578ed

Comments (0)

Files changed (12)

File workshop-3/prs1.py

-"""
-    Paper Rock Scissors v1
-
-    Requirements:
-        1) computer is always rock
-        2) ask user for input
-        3) tell the user the resul
-
-"""
-
-comp_choice = 'rock'
-user = raw_input('Enter a choice (rock, scissor, paper): ')
-if user == 'rock':
-	print 'DRAW'
-elif user == 'scissor':
-	print 'U LOST'
-elif user == 'paper':
-	print 'U WON'
-else: # user chooses some weird choice
-	print 'dude wtf is {c}'.format(c=user)
-

File workshop-3/prs2.py

-"""
-    Paper Rock Scissors v2
-    
-    Requirements:
-        1) let computer chooses (google Python random.choice, it takes a list of choices)
-        2) ask user for input
-        3) tell the user the result
-"""
-import random
-#from random import choice
-
-choices =  ['rock', 'scissor', 'paper']
-
-comp_choice = random.choice(choices)
-print 'Computer chose {c}'.format(c=comp_choice)
-
-# you can also do
-#comp_choice = random.choice(['rock', 'scissor', 'paper'])
-
-user = raw_input('Enter a choice (rock, scissor, paper): ')
-if user == comp_choice:
-	print 'DRAW'
-elif user == 'scissor' and comp_choice == 'paper':
-	print 'U WON'
-elif user == 'scissor' and comp_choice == 'rock':
-	print 'U LOST'
-elif user == 'rock' and comp_choice == 'paper':
-	print 'U LOST'
-elif user == 'rock' and comp_choice == 'scissor':
-	print 'U WON'
-elif user == 'paper' and comp_choice == 'rock':
-	print 'U WON'
-elif user == 'paper' and comp_choice == 'scissor':
-	print 'U LOST'
-else: # user chooses some weird choice
-	print 'dude wtf is {c}'.format(c=user)
-
-# can we simplify this?

File workshop-3/prs3.py

-"""
-    Paper Rock Scissors v3
-
-    Requirements:
-        Does what v2 do, except, the input is abbrv into p, r, s for paper, rock, scissor
-"""
-import random
-#from random import choice
-
-choices =  ['r', 's', 'p']
-
-comp_choice = random.choice(choices)
-print 'Computer chose {c}'.format(c=comp_choice)
-
-# you can also do
-#comp_choice = random.choice(['rock', 'scissor', 'paper'])
-
-user = raw_input('Enter a choice (r=rock, s=scissor, p=paper): ')
-print 'Computer chose {c}'.format(c=comp_choice)
-if user == comp_choice:
-	print 'DRAW'
-elif user == 's' and comp_choice == 'p':
-	print 'U WON'
-elif user == 's' and comp_choice == 'r':
-	print 'U LOST'
-elif user == 'r' and comp_choice == 'p':
-	print 'U LOST'
-elif user == 'r' and comp_choice == 's':
-	print 'U WON'
-elif user == 'p' and comp_choice == 'r':
-	print 'U WON'
-elif user == 'p' and comp_choice == 's':
-	print 'U LOST'
-
-# can we simplify this?
-# can we have another way to do look-up? dictionary in python can help

File workshop-3/prs4.py

-"""
-    Paper Rock Scissors v4
-
-    Requirements:
-        1) ask user whether they want to play the game or not
-        2) does what v3 does
-        3) ask user again whether they want to continue the game or not
-
-"""
-import random
-#from random import choice
-
-cont = raw_input('Do you want to play? yes/no: ')
-
-while cont == 'yes':
-	choices =  ['r', 's', 'p']
-
-	comp_choice = random.choice(choices)
-	# you can also do
-	#comp_choice = random.choice(['rock', 'scissor', 'paper'])
-
-	user = raw_input('Enter a choice (r=rock, s=scissor, p=paper): ')
-	print 'Computer chose {c}'.format(c=comp_choice)
-
-	if user == comp_choice:
-		print 'DRAW'
-	elif user == 's' and comp_choice == 'p':
-		print 'U WON'
-	elif user == 's' and comp_choice == 'r':
-		print 'U LOST'
-	elif user == 'r' and comp_choice == 'p':
-		print 'U LOST'
-	elif user == 'r' and comp_choice == 's':
-		print 'U WON'
-	elif user == 'p' and comp_choice == 'r':
-		print 'U WON'
-	elif user == 'p' and comp_choice == 's':
-		print 'U LOST'
-	cont = raw_input('Do you want to continue this game? yes/no: ')
-
-# can we simplify this?
-# can we have another way to do look-up? dictionary in python can help

File workshop-3/prs5.py

-"""
-    Paper Rock Scissors v5
-
-    Requirements:
-        everything as v4 but handles bad inputs (what if user says pp instead of p?)
-
-"""
-import random
-#from random import choice
-
-cont = raw_input('Do you want to play? yes/no: ')
-
-while cont == 'yes':
-	choices =  ['r', 's', 'p']
-
-	comp_choice = random.choice(choices)
-
-	# you can also do
-	#comp_choice = random.choice(['rock', 'scissor', 'paper'])
-
-	user = raw_input('Enter a choice (r=rock, s=scissor, p=paper): ')
-	print 'Computer chose {c}'.format(c=comp_choice)
-
-	if user not in choices:
-		print 'Your input choice {c} is invalid. Only r, s and p are acceptable!.'.format(c=user)
-	if user == comp_choice:
-		print 'DRAW'
-	elif user == 's' and comp_choice == 'p':
-		print 'U WON'
-	elif user == 's' and comp_choice == 'r':
-		print 'U LOST'
-	elif user == 'r' and comp_choice == 'p':
-		print 'U LOST'
-	elif user == 'r' and comp_choice == 's':
-		print 'U WON'
-	elif user == 'p' and comp_choice == 'r':
-		print 'U WON'
-	elif user == 'p' and comp_choice == 's':
-		print 'U LOST'
-	cont = raw_input('Do you want to continue this game? yes/no: ')
-
-# can we simplify this?
-# can we have another way to do look-up? dictionary in python can help

File workshop-3/prs5_v2.py

-"""
-    Paper Rock Scissors v5 simplification
-	(Jacky did this)
-	
-    Requirements:
-        everything as v5 and v4 simplified the condition statements.
-
-"""
-import random
-#from random import choice
-
-cont = raw_input('Do you want to play? yes/no: ')
-
-while cont == 'yes':
-	choices =  ['r', 's', 'p']
-
-	comp_choice = random.choice(choices)
-	# you can also do
-	#comp_choice = random.choice(['rock', 'scissor', 'paper'])
-
-	user = raw_input('Enter a choice (r=rock, s=scissor, p=paper): ')
-	print 'Computer chose {c}'.format(c=comp_choice)
-
-	if user not in choices:
-		print 'Your input choice {c} is invalid. Only r, s and p are acceptable!.'.format(c=user)
-	if user == comp_choice:
-		print 'DRAW'
-	elif user == 's' and comp_choice == 'p':
-		print 'U WON'
-	elif user == 'r' and comp_choice == 's':
-		print 'U WON'
-	elif user == 'p' and comp_choice == 'r':
-		print 'U WON'
-	else:  # credit to Jacky's work
-		print 'U LOST'
-	cont = raw_input('Do you want to continue this game? yes/no: ')
-
-
-

File workshop-3/solutions/prs1.py

+"""
+    Paper Rock Scissors v1
+
+    Requirements:
+        1) computer is always rock
+        2) ask user for input
+        3) tell the user the resul
+
+"""
+
+comp_choice = 'rock'
+user = raw_input('Enter a choice (rock, scissor, paper): ')
+if user == 'rock':
+	print 'DRAW'
+elif user == 'scissor':
+	print 'U LOST'
+elif user == 'paper':
+	print 'U WON'
+else: # user chooses some weird choice
+	print 'dude wtf is {c}'.format(c=user)
+

File workshop-3/solutions/prs2.py

+"""
+    Paper Rock Scissors v2
+    
+    Requirements:
+        1) let computer chooses (google Python random.choice, it takes a list of choices)
+        2) ask user for input
+        3) tell the user the result
+"""
+import random
+#from random import choice
+
+choices =  ['rock', 'scissor', 'paper']
+
+comp_choice = random.choice(choices)
+print 'Computer chose {c}'.format(c=comp_choice)
+
+# you can also do
+#comp_choice = random.choice(['rock', 'scissor', 'paper'])
+
+user = raw_input('Enter a choice (rock, scissor, paper): ')
+if user == comp_choice:
+	print 'DRAW'
+elif user == 'scissor' and comp_choice == 'paper':
+	print 'U WON'
+elif user == 'scissor' and comp_choice == 'rock':
+	print 'U LOST'
+elif user == 'rock' and comp_choice == 'paper':
+	print 'U LOST'
+elif user == 'rock' and comp_choice == 'scissor':
+	print 'U WON'
+elif user == 'paper' and comp_choice == 'rock':
+	print 'U WON'
+elif user == 'paper' and comp_choice == 'scissor':
+	print 'U LOST'
+else: # user chooses some weird choice
+	print 'dude wtf is {c}'.format(c=user)
+
+# can we simplify this?

File workshop-3/solutions/prs3.py

+"""
+    Paper Rock Scissors v3
+
+    Requirements:
+        Does what v2 do, except, the input is abbrv into p, r, s for paper, rock, scissor
+"""
+import random
+#from random import choice
+
+choices =  ['r', 's', 'p']
+
+comp_choice = random.choice(choices)
+print 'Computer chose {c}'.format(c=comp_choice)
+
+# you can also do
+#comp_choice = random.choice(['rock', 'scissor', 'paper'])
+
+user = raw_input('Enter a choice (r=rock, s=scissor, p=paper): ')
+print 'Computer chose {c}'.format(c=comp_choice)
+if user == comp_choice:
+	print 'DRAW'
+elif user == 's' and comp_choice == 'p':
+	print 'U WON'
+elif user == 's' and comp_choice == 'r':
+	print 'U LOST'
+elif user == 'r' and comp_choice == 'p':
+	print 'U LOST'
+elif user == 'r' and comp_choice == 's':
+	print 'U WON'
+elif user == 'p' and comp_choice == 'r':
+	print 'U WON'
+elif user == 'p' and comp_choice == 's':
+	print 'U LOST'
+
+# can we simplify this?
+# can we have another way to do look-up? dictionary in python can help

File workshop-3/solutions/prs4.py

+"""
+    Paper Rock Scissors v4
+
+    Requirements:
+        1) ask user whether they want to play the game or not
+        2) does what v3 does
+        3) ask user again whether they want to continue the game or not
+
+"""
+import random
+#from random import choice
+
+cont = raw_input('Do you want to play? yes/no: ')
+
+while cont == 'yes':
+	choices =  ['r', 's', 'p']
+
+	comp_choice = random.choice(choices)
+	# you can also do
+	#comp_choice = random.choice(['rock', 'scissor', 'paper'])
+
+	user = raw_input('Enter a choice (r=rock, s=scissor, p=paper): ')
+	print 'Computer chose {c}'.format(c=comp_choice)
+
+	if user == comp_choice:
+		print 'DRAW'
+	elif user == 's' and comp_choice == 'p':
+		print 'U WON'
+	elif user == 's' and comp_choice == 'r':
+		print 'U LOST'
+	elif user == 'r' and comp_choice == 'p':
+		print 'U LOST'
+	elif user == 'r' and comp_choice == 's':
+		print 'U WON'
+	elif user == 'p' and comp_choice == 'r':
+		print 'U WON'
+	elif user == 'p' and comp_choice == 's':
+		print 'U LOST'
+	cont = raw_input('Do you want to continue this game? yes/no: ')
+
+# can we simplify this?
+# can we have another way to do look-up? dictionary in python can help

File workshop-3/solutions/prs5.py

+"""
+    Paper Rock Scissors v5
+
+    Requirements:
+        everything as v4 but handles bad inputs (what if user says pp instead of p?)
+
+"""
+import random
+#from random import choice
+
+cont = raw_input('Do you want to play? yes/no: ')
+
+while cont == 'yes':
+	choices =  ['r', 's', 'p']
+
+	comp_choice = random.choice(choices)
+
+	# you can also do
+	#comp_choice = random.choice(['rock', 'scissor', 'paper'])
+
+	user = raw_input('Enter a choice (r=rock, s=scissor, p=paper): ')
+	print 'Computer chose {c}'.format(c=comp_choice)
+
+	if user not in choices:
+		print 'Your input choice {c} is invalid. Only r, s and p are acceptable!.'.format(c=user)
+	if user == comp_choice:
+		print 'DRAW'
+	elif user == 's' and comp_choice == 'p':
+		print 'U WON'
+	elif user == 's' and comp_choice == 'r':
+		print 'U LOST'
+	elif user == 'r' and comp_choice == 'p':
+		print 'U LOST'
+	elif user == 'r' and comp_choice == 's':
+		print 'U WON'
+	elif user == 'p' and comp_choice == 'r':
+		print 'U WON'
+	elif user == 'p' and comp_choice == 's':
+		print 'U LOST'
+	cont = raw_input('Do you want to continue this game? yes/no: ')
+
+# can we simplify this?
+# can we have another way to do look-up? dictionary in python can help

File workshop-3/solutions/prs5_v2.py

+"""
+    Paper Rock Scissors v5 simplification
+	(Jacky did this)
+	
+    Requirements:
+        everything as v5 and v4 simplified the condition statements.
+
+"""
+import random
+#from random import choice
+
+cont = raw_input('Do you want to play? yes/no: ')
+
+while cont == 'yes':
+	choices =  ['r', 's', 'p']
+
+	comp_choice = random.choice(choices)
+	# you can also do
+	#comp_choice = random.choice(['rock', 'scissor', 'paper'])
+
+	user = raw_input('Enter a choice (r=rock, s=scissor, p=paper): ')
+	print 'Computer chose {c}'.format(c=comp_choice)
+
+	if user not in choices:
+		print 'Your input choice {c} is invalid. Only r, s and p are acceptable!.'.format(c=user)
+	if user == comp_choice:
+		print 'DRAW'
+	elif user == 's' and comp_choice == 'p':
+		print 'U WON'
+	elif user == 'r' and comp_choice == 's':
+		print 'U WON'
+	elif user == 'p' and comp_choice == 'r':
+		print 'U WON'
+	else:  # credit to Jacky's work
+		print 'U LOST'
+	cont = raw_input('Do you want to continue this game? yes/no: ')
+
+
+