Sep-13-2019, 12:51 PM
(Sep-13-2019, 12:40 PM)ichabod801 Wrote:
- 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')
Hello sir!
You said I was comparing an integer to a string, and that was causing problem. This has happened with me before. I'm almost too new, could you please tell how to compare integer to integer? Please just send me the correction of that part, since I don't know how to do any other corrections you told. Thank you!