python Inf 124 - Proj 2 - view.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Inf 124 - Proj 2 - view.py相关的知识,希望对你有一定的参考价值。

# view.py - Display state to user

def get_choice_index_from_option_menu(option_list, question):
    '''Prints a menu of options determined by the list with a question prompt and return the user's choice as the index of the selected item (index based on option_list)'''
    validOptions = ""

    print('')
    for i in range(len(option_list)): 
        validOptions = validOptions + str(i)
        print('{}.{}'.format(i+1, option_list[i]))
    print('')

    choice = str(input(question)-1)

    # check if the choice is valid before returning the chosen index (index-1)
    if choice != "" and choice in validOptions:
        return int(choice)
    else:
        # raise exception
        pass

def get_client_name():
    ''' Asks the client for their name and returns it '''
    return raw_input('What is your name?')

以上是关于python Inf 124 - Proj 2 - view.py的主要内容,如果未能解决你的问题,请参考以下文章

python Inf 124 - Proj 2 - 测试状态,聊天会话,客户端类

python proj utm2wgs wgs2utm

python proj utm2wgs wgs2utm

leetcode-124-二叉树中的最大路径和

LeetCode 124. 二叉树中的最大路径和 | Python

python proj utm2wgs wgs2utm