Sep-13-2019, 12:40 PM
- Your randomization isn't working because randint returns an int, and you are comparing that to strings.
- Better would be
random.choice('rps')
, it just gives you what you need in one line.
- Globals lead to confusing and hard to maintain code. Pass parameters and assign return values. See the function tutorial for more details.
- For multiple comparisons in is often [the best choice:
if rps not in ('r', 'p', 's'):
.
- RPS is a great place to learn dictionaries instead of complicated if/elif/else:
wins = {'r': 's', 'p': 'r', 's': 'p'} if rps = ai: print('tie') elif wins[ai] == rps: print('win') else: print('loss')
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures