2017-09-06 65 views
-4

我想用一个代码随机模块我目前正在设法解决:Python的随机模块功能

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.""" 

需要找到随机部分的代码,以解决它

完整代码:http://www.codeskulptor.org/#user43_rc6Pm3n7uj_0.py

+0

什么'random_computer_choice'应该做什么?它预计不会有任何争论。 – Grigoriy

+1

对“随机”模块有什么不了解?一个简单的'random.randint(0,2)'会得到你想要的结果。 – abccd

回答

4

OP有比较奇怪的任务。但我认为OP的意思是这样的:

def random_computer_choice(): 
    """Choose randomly for computer.""" 
    return random.choice(['rock','paper','scissors'])