From fa78bcbf1bde44661e45b4719e7611e342c525a1 Mon Sep 17 00:00:00 2001 From: Junior Date: Thu, 27 Jun 2024 11:08:13 -0400 Subject: [PATCH] Show examples of docstrings. --- Python/029_scope.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Python/029_scope.py b/Python/029_scope.py index fb8e800..165b066 100644 --- a/Python/029_scope.py +++ b/Python/029_scope.py @@ -15,7 +15,16 @@ MAX_STUDENTS_PER_TEACHER = 25 # Let's create a couple functions to get values # This function makes use of the MAX_TEACHERS global variable -def get_teacher_count(): +# This is also an example of a "docstring". A docstring is text +# that is displayed in the IDE and provides additional information +# to the coder about what the function does and what it returns. +def get_teacher_count() -> int: + """ + Returns the number of teachers at the school. + + Returns: + int: The number of teachers as provided by user input. Value restricted to MAX_TEACHERS. + """ count = 0 while count == 0: # Get a value from the user @@ -35,7 +44,20 @@ def get_teacher_count(): # This function makes use of the MAX_STUDENTS_PER_TEACHER global variable # and is passed the number of teachers obtained from get_teacher_count() -def get_student_count(teacher_count: int): +def get_student_count(teacher_count: int) -> int: + """ + Get the number of students at the school from user input. + + Number will be restricted to: + * teacher_count at a minimum, + * (teacher_count * MAX_STUDENTS_PER_TEACHER) as a maximum. + + Arguments: + teacher_count (int): The number of teachers at the school. + + Returns: + int: The number of students at the school. + """ count = 0 # Can't have fewer students than teachers min_students = teacher_count