-4

例子:

choice(['Aa', 'Bb', 'Cc')

应该打印:

Enter choice: Aa
Enter choice: Cc
Enter choice: Aa
Enter choice: Aa
Enter choice: Bb
Enter choice: Cc
Enter choice: Aa
Enter choice:

There are 4 choices for Aa.

There are 2 choices for Cc.

There are 1 choices for Bb.

There is 1 choice for Unknown.

请注意,它会一直询问您的选择是什么,直到出现空白为止。

至今:

默认选择(n):

while True:

    vote = input('Enter choice: ')
4

1 回答 1

1

这听起来很像家庭作业,所以这里有一些伪代码:

function choice gets an options list

    counter is a dictionary
    for each option in the options list
        counter[option] is 0
    counter[unknown] is 0

    loop
        ask for input
        if input is blank
            exit the loop
        otherwise if input is in the option array
            increment counter[input]
        otherwise
            increment counter[unknown]

    for each option in the options list
        "Option {option} had {counter[option]} votes"
    "Option unknown had {counter[unknown]} votes"
于 2012-05-25T00:29:13.790 回答