Skip to content

Commit 9e9cb0b

Browse files
author
Kareem Zidane
committed
update cs50 docstrings
1 parent 1440ae5 commit 9e9cb0b

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/cs50/cs50.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55

66

77
def get_float(prompt):
8+
"""Reads a line of text from standard input and returns the equivalent float as precisely as
9+
possible; if text does not represent a float, user is prompted to retry. If line can't be read,
10+
returns None.
11+
12+
:type prompt: str
13+
814
"""
9-
Read a line of text from standard input and return the equivalent float
10-
as precisely as possible; if text does not represent a double, user is
11-
prompted to retry. If line can't be read, return None.
12-
"""
15+
1316
while True:
1417
try:
1518
return _get_float(prompt)
@@ -29,11 +32,12 @@ def _get_float(prompt):
2932

3033

3134
def get_int(prompt):
35+
"""Reads a line of text from standard input and return the equivalent int; if text does not
36+
represent an int, user is prompted to retry. If line can't be read, returns None.
37+
38+
:type prompt: str
3239
"""
33-
Read a line of text from standard input and return the equivalent int;
34-
if text does not represent an int, user is prompted to retry. If line
35-
can't be read, return None.
36-
"""
40+
3741
while True:
3842
try:
3943
return _get_int(prompt)
@@ -53,12 +57,13 @@ def _get_int(prompt):
5357

5458

5559
def get_string(prompt):
60+
"""Reads a line of text from standard input and returns it as a string, sans trailing line
61+
ending. Supports CR (\r), LF (\n), and CRLF (\r\n) as line endings. If user inputs only a line
62+
ending, returns "", not None. Returns None upon error or no input whatsoever (i.e., just EOF).
63+
64+
:type prompt: str
5665
"""
57-
Read a line of text from standard input and return it as a string,
58-
sans trailing line ending. Supports CR (\r), LF (\n), and CRLF (\r\n)
59-
as line endings. If user inputs only a line ending, returns "", not None.
60-
Returns None upon error or no input whatsoever (i.e., just EOF).
61-
"""
66+
6267
if not isinstance(prompt, str):
6368
raise TypeError("prompt must be of type str")
6469

@@ -73,8 +78,7 @@ def _get_input(prompt):
7378

7479

7580
class _flushfile():
76-
"""
77-
Disable buffering for standard output and standard error.
81+
""" Disable buffering for standard output and standard error.
7882
http://stackoverflow.com/a/231216
7983
"""
8084

@@ -91,7 +95,8 @@ def write(self, data):
9195

9296

9397
def disable_output_buffering():
94-
"""Disables output buffering to prevent prompts from being buffered"""
98+
"""Disables output buffering to prevent prompts from being buffered.
99+
"""
95100
sys.stderr = _flushfile(sys.stderr)
96101
sys.stdout = _flushfile(sys.stdout)
97102

0 commit comments

Comments
 (0)