我想将随机模块用于我目前正在尝试解决的代码:
def choice_to_number(choice):
"""Convert choice to number."""
# If choice is 'rock', give me 0
# If choice is 'paper', give me 1
# If choice is 'scissors', give me 2
if choice == 'rock':
return 0
elif choice == 'paper':
return 1
else:
return 2
def number_to_choice(number):
"""Convert number to choice."""
# If number is 0, give me 'rock'
# If number is 1, give me 'paper'
# If number is 2, give me 'scissors'
if number == 0:
return 'rock'
elif number == 1:
return 'paper'
else:
return 'scissors'
def random_computer_choice():
"""Choose randomly for computer."""
需要找到随机部分的代码才能解决它
答案 0 :(得分:4)
def random_computer_choice():
"""Choose randomly for computer."""
return random.choice(['rock','paper','scissors'])