Commits

Yeuk Hon Wong committed f91e895 Draft

Replaced tab with spaces.

Comments (0)

Files changed (2)

workshop-3/solutions/prs5.py

 cont = raw_input('Do you want to play? yes/no: ')
 
 while cont == 'yes':
-	choices =  ['r', 's', 'p']
+    choices =  ['r', 's', 'p']
+    comp_choice = random.choice(choices)
 
-	comp_choice = random.choice(choices)
+    # you can also do
+    #comp_choice = random.choice(['rock', 'scissor', 'paper'])
 
-	# 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)
 
-	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: ')
+    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

workshop-3/solutions/prs5_v2.py

 cont = raw_input('Do you want to play? yes/no: ')
 
 while cont == 'yes':
-	choices =  ['r', 's', 'p']
+    choices =  ['r', 's', 'p']
+    
+    comp_choice = random.choice(choices)
+    # you can also do
+    #comp_choice = random.choice(['rock', 'scissor', 'paper'])
 
-	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)
 
-	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: ')
-
-
-
+    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: ')