How to create a voting system to define the best day for a meeting without libraries

48 Views Asked by At

I need to create a voting system for the best suitable weekday for a meeting using only built-in functions. For that, I've created the following dictionary:

days = {'Sunday':0,
        'Monday':1,
        'Tuesday':2,
        'Wednesday':3,
        'Thursday':4,
        'Friday':5,
        'Saturday':6}

Each individual would choose the most convenient day for them by inputting a corresponding number. Also, by inserting -5, the program would print the number of votes each day got as well as the winner:

Input:

1
3
3
5
5
5
0
6
-5

Output:

Sunday = 1
Monday = 1
Tuesday = 0
Wednesday = 2
Thursday = 0
Friday = 3
Saturday = 1
The winner is Friday.

Ties can be disregarded.

As I'm a beginner, I don't know if dictionaries are the best solution. Any suggestions?

1

There are 1 best solutions below

0
samology On

I have just solved a similar question. Yours is slightly different because you don't want to use any libraries.

The Code is:

day_dict = {}
day_list = []
day = ""
while True:
    day = input("Enter the day you want to meet (type DONE to terminate): ")
    if day == "DONE":
        break
    else:
        print("You have chosen: {}".format(day))
        day_list.append(day)

for each_day in day_list:
    day_dict[each_day] = day_dict.get(each_day,0)+1
    
for key,value in day_dict.items():
    print("\n{:<10} has been chosen {:<2}{:<2} time/s.".format(key,"",value))

Note that they have to enter the day names, and to quite by typing "DONE", if you insist in your version, go ahead and change it.