1. Build the first part of the main function rpsls(name) that converts name into the number player_number between 0 and 4 using the helper function name_to_number.
2. Build the second part of rpsls(name) that generates a random number comp_number between 0 and 4 using the function random.randrange(). I suggest experimenting with randrange in a separate CodeSkulptor window before deciding on how to call it to make sure that you do not accidently generate numbers in the wrong range.
2. Build the last part of rpsls(name) that determines and prints out the winner. This test is actually very simple if you apply modular arithmetic (% in Python) to the difference between comp_number and player_number. If this is not immediately obvious to you, I would suggest reviewing our discussion of remainder and modular arithmetic and experimenting with the remainder operator % in a separate CodeSkulptor window to understand its behavior.
This is the code i have created so far:
def number_to_name(number): if number == 0: return "rock" #I dont want to paste all the code due to other students but i hope you get the idea. def name_to_number(name): # fill in your code below if name == "rock": return 0 #What i needed to do is implement step one into the following function... def rpsls(name): # fill in your code below # convert name to player_number using name_to_number # compute random guess for comp_number using random.randrange() # compute difference of player_number and comp_number modulo five # use if/elif/else to determine winner # convert comp_number to name using number_to_name # print results
So can someone help me get started with the function rpsls, or the least help me get started in the right direction. I would greatly appreciate it. I just have no idea how to start or to implement modulo. Thanks for the help!