Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs1-25sp
lecture-code
Commits
ff065e5d
Commit
ff065e5d
authored
4 weeks ago
by
Jedidiah Tsang
Browse files
Options
Download
Email Patches
Plain Diff
Add lecture code
parent
1eceb5b5
master
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
16/vote_counter.py
+41
-0
16/vote_counter.py
manifest.json
+2
-1
manifest.json
with
43 additions
and
1 deletion
+43
-1
16/vote_counter.py
0 → 100644
View file @
ff065e5d
import
math
from
collections
import
Counter
def
process_votes
()
->
tuple
[
Counter
,
str
|
None
]:
"""
Takes in votes from the voters, and processes the winner.
Returns:
tuple[Counter, str | None]: A Counter where the keys are the possible
options someone could vote for. The value associated with each option
is the number of people who voted for that option.
"""
vote_tracker
=
{}
#Solicit votes
done
:
bool
=
False
while
not
done
:
choice
:
str
=
input
(
"Hi there. Which ice cream flavor is your favorite? "
).
lower
()
if
choice
not
in
vote_tracker
:
vote_tracker
[
choice
]
=
0
vote_tracker
[
choice
]
+=
1
more_votes
:
str
=
input
(
"Your vote has been registered. Are there more votes to process? Y/N "
).
upper
()
if
more_votes
==
"N"
:
done
=
True
#Determine the winning option
max_votes
=
-
math
.
inf
winning_option
=
None
for
option
in
vote_tracker
:
num_votes
=
vote_tracker
[
option
]
if
num_votes
>
max_votes
:
max_votes
=
num_votes
winning_option
=
option
return
(
vote_tracker
,
winning_option
)
results
=
process_votes
()
if
results
[
1
]
!=
None
:
print
(
"The winning option is..."
,
results
[
1
]
+
"!!!!!"
)
This diff is collapsed.
Click to expand it.
manifest.json
View file @
ff065e5d
...
...
@@ -4,7 +4,8 @@
"00/experimenting.py"
,
"00/main.py"
,
"12/physics.py"
,
"13/monty.py"
"13/monty.py"
,
"16/vote_counter.py"
],
"ignore"
:
[]
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help