Skip to content

Commit fd9b7bf

Browse files
committed
Added docstrings to exemplars and stubs. Changed some exemplar code to conform to Pylint nags.
1 parent 3482723 commit fd9b7bf

6 files changed

Lines changed: 222 additions & 28 deletions

File tree

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
def round_scores(student_scores):
2+
'''
3+
:param student_scores: list of student exam scores as float or int.
4+
:return: list of student scores *rounded* to nearest integer value.
5+
'''
6+
27
rounded = []
38
while student_scores:
49
rounded.append(round(student_scores.pop()))
510
return rounded
611

712

813
def count_failed_students(student_scores):
14+
'''
15+
:param student_scores: list of integer student scores.
16+
:return: integer count of student scores at or below 40.
17+
'''
18+
919
non_passing = 0
1020
for score in student_scores:
1121
if score <= 40:
@@ -14,14 +24,26 @@ def count_failed_students(student_scores):
1424

1525

1626
def above_threshold(student_scores, threshold):
17-
above_threshold = []
27+
'''
28+
:param student_scores: list of integer scores
29+
:param threshold : integer
30+
:return: list of integer scores that are at or above the "best" threshold.
31+
'''
32+
33+
above = []
34+
1835
for score in student_scores:
1936
if score >= threshold:
20-
above_threshold.append(score)
21-
return above_threshold
37+
above.append(score)
38+
return above
2239

2340

2441
def letter_grades(highest):
42+
'''
43+
:param highest: integer of highest exam score.
44+
:return: list of integer score thresholds for each F-A letter grades.
45+
'''
46+
2547
increment = round((highest - 40)/4)
2648
scores = []
2749
for score in range(41, highest, increment):
@@ -30,20 +52,31 @@ def letter_grades(highest):
3052

3153

3254
def student_ranking(student_scores, student_names):
55+
'''
56+
:param student_scores: list of scores in descending order.
57+
:param student_names: list of names in descending order by exam score.
58+
:return: list of strings in format ["<rank>. <student name>: <score>"].
59+
'''
60+
3361
results = []
3462
for index, name in enumerate(student_names):
3563
rank_string = str(index + 1) + ". " + name + ": " + str(student_scores[index])
3664
results.append(rank_string)
37-
#results.append(f"{index + 1}. {name}: {student_scores[index]}")
65+
3866
return results
3967

4068

4169
def perfect_score(student_info):
70+
'''
71+
:param student_info: list of [<student name>, <score>] lists
72+
:return: First [<student name>, 100] found OR "No perfect score."
73+
'''
74+
4275
result = "No perfect score."
76+
4377
for item in student_info:
4478
if item[1] == 100:
4579
result = item
4680
break
47-
else:
48-
continue
81+
4982
return result

exercises/concept/making-the-grade/loops.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ def round_scores(student_scores):
33
:param student_scores: list of student exam scores as float or int.
44
:return: list of student scores *rounded* to nearest integer value.
55
'''
6+
67
pass
78

89
def count_failed_students(student_scores):
910
'''
1011
:param student_scores: list of integer student scores.
1112
:return: integer count of student scores at or below 40.
1213
'''
14+
1315
pass
1416

1517
def above_threshold(student_scores, threshold):
@@ -18,21 +20,26 @@ def above_threshold(student_scores, threshold):
1820
:param threshold : integer
1921
:return: list of integer scores that are at or above the "best" threshold.
2022
'''
23+
2124
pass
2225

2326
def letter_grades(highest):
2427
'''
2528
:param highest: integer of highest exam score.
2629
:return: list of integer score thresholds for each F-A letter grades.
2730
'''
31+
2832
pass
33+
2934
def student_ranking(student_scores, student_names):
3035
'''
3136
:param student_scores: list of scores in descending order.
3237
:param student_names: list of names in descending order by exam score.
3338
:return: list of strings in format ["<rank>. <student name>: <score>"].
3439
'''
40+
3541
pass
42+
3643
def perfect_score(student_info):
3744
'''
3845
:param student_info: list of [<student name>, <score>] lists
Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,87 @@
1+
12
def new_seating_chart(size=22):
2-
seats = dict()
3-
for number in range(1, size+1):
4-
seats[number] = None
5-
return seats
3+
'''
4+
5+
:param size: int - number if seats in the seating chart.
6+
:return: dict - with number of seats specified, and placeholder values.
7+
'''
8+
9+
return {number: None for number in range(1, size+1) }
10+
611

712
def arrange_reservations(guests=None):
8-
if guests is None:
9-
return new_seating_chart()
10-
else:
11-
seats = new_seating_chart()
13+
'''
14+
15+
:param guest_list: list - list of guest names for reservations.
16+
:return: dict - Default sized dictionary with guests assigned seats,
17+
and placeholders for empty seats.
18+
'''
19+
20+
seats = new_seating_chart()
21+
22+
if guests:
1223
for seat_number in range(1, len(guests)):
1324
seats[seat_number] = guests[seat_number]
1425
return seats
1526

27+
1628
def find_all_available_seats(seats):
29+
'''
30+
31+
:param seats: dict - seating chart.
32+
:return: list - list of seat numbers available for reserving..
33+
'''
34+
1735
available = []
1836
for seat_num, value in seats.items():
1937
if value is None:
2038
available.append(seat_num)
2139
return available
2240

41+
2342
def curr_empty_seat_capacity(seats):
43+
'''
44+
45+
:param seats: dict - dictionary of reserved seats.
46+
:return: int - number of seats empty.
47+
'''
48+
2449
count = 0
2550
for value in seats.values():
2651
if value is None:
2752
count += 1
2853
return count
2954

55+
3056
def accommodate_waiting_guests(seats, guests):
57+
'''
58+
59+
:param seats: dict - seating chart dictionary.
60+
:param guests: list - walk-in guests
61+
:return: dict - updated seating chart with available spaces filled.
62+
'''
63+
3164
curr_empty_seats = curr_empty_seat_capacity(seats)
3265
empty_seat_list = find_all_available_seats(seats)
66+
3367
if len(guests) > curr_empty_seats:
3468
return False
3569
else:
36-
for index in range(len(guests)):
70+
for index, item in enumerate(guests):
3771
seats[empty_seat_list[index]] = guests[index]
72+
3873
return seats
3974

75+
4076
def empty_seats(seats, seat_numbers):
41-
for seat in seat_numbers:
42-
seats[seat] = None
43-
return seats
77+
'''
78+
79+
:param seats: dict - seating chart dictionary.
80+
:param seat_numbers: list - list of seat numbers to free up or empty.
81+
:return: updated seating chart dictionary.
82+
'''
83+
84+
for seat in seat_numbers:
85+
seats[seat] = None
86+
87+
return seats
Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,57 @@
1-
def new_seating_chart():
1+
def new_seating_chart(size=22):
2+
'''
3+
4+
:param size: int - number if seats in the seating chart. Default is 22.
5+
:return: dict - with number of seats specified, and placeholder values.
6+
'''
7+
8+
pass
9+
10+
def arrange_reservations(guest_list):
11+
'''
12+
13+
:param guest_list: list - list of guest names for reservations.
14+
:return: dict - Default sized dictionary with guests assigned seats,
15+
and placeholders for empty seats.
16+
'''
17+
18+
pass
19+
20+
def find_all_available_seats(seats):
21+
'''
22+
23+
:param seats: dict - seating chart.
24+
:return: list - list of seat numbers available for reserving..
25+
'''
26+
227
pass
328

4-
def arrange_reservations():
29+
def current_seating_capacity(seats):
30+
'''
31+
32+
:param seats: dict - dictionary of reserved seats.
33+
:return: int - number of seats empty.
34+
'''
35+
536
pass
637

7-
def find_all_available_seats():
8-
pass
38+
def accommodate_waiting_guests(seats, guests):
39+
'''
940
10-
def current_seating_capacity():
11-
pass
41+
:param seats: dict - seating chart dictionary.
42+
:param guests: list - walk-in guests
43+
:return: dict - updated seating chart with available spaces filled.
44+
'''
1245

13-
def accommodate_waiting_guests():
14-
pass
15-
def empty_seats():
1646
pass
47+
48+
49+
def empty_seats(seats, seat_numbers):
50+
'''
51+
52+
:param seats: dict - seating chart dictionary.
53+
:param seat_numbers: list - list of seat numbers to free up or empty.
54+
:return: updated seating chart dictionary.
55+
'''
56+
57+
pass
Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,58 @@
11
def get_coordinate(record):
2+
'''
3+
4+
:param record: tuple - a (treasure, coordinate) pair.
5+
:return: str - the extracted map coordinate.
6+
'''
7+
28
return record[1]
39

10+
411
def convert_coordinate(coordinate):
12+
'''
13+
14+
:param coordinate: str - a string map coordinate
15+
:return: tuple - the string coordinate seperated into its individual components.
16+
'''
17+
518
return tuple(coordinate)
619

20+
721
def compare_records(azara_record, rui_record):
22+
'''
23+
24+
:param azara_record: tuple - a (treasure, coordinate) pair.
25+
:param rui_record: tuple - a (location, coordinate, quadrant) trio.
26+
:return: bool - True if coordinates match, False otherwise.
27+
'''
28+
829
return convert_coordinate(azara_record[1]) in rui_record
930

31+
1032
def create_record(azara_record, rui_record):
33+
'''
34+
35+
:param azara_record: tuple - a (treasure, coordinate) pair.
36+
:param rui_record: tuple - a (location, coordinate, quadrant) trio.
37+
:return: tuple - combined record, or "not a match" if the records are incompatible.
38+
'''
39+
1140
if compare_records(azara_record, rui_record):
1241
return azara_record + rui_record
1342
else:
1443
return "not a match"
1544

45+
1646
def clean_up(combined_record_group):
47+
'''
48+
49+
:param combined_record_group: tuple of tuples - everything from both participants.
50+
:return: tuple of tuples - everything "cleaned", with excess coordinates and information removed.
51+
'''
1752

1853
report = ""
54+
1955
for item in combined_record_group:
20-
report += f"{(item[0], item[2], item[3], item[4])}\n"
56+
report += f"{(item[0], item[2], item[3], item[4])}\n"
57+
2158
return report

0 commit comments

Comments
 (0)