You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on the lines.py problem in CS50P, and I encountered an issue with the check50 tests. When I include logic to skip docstrings (lines starting with """ or '''), the check50 test fails for the case where the file contains docstrings. However, if I remove the docstring-checking logic, the tests pass.
It gives me the following errors:
:( lines.py yields 9 given a file with 9 lines, whitespace, comments, and docstrings expected "9", not "1\n".
:| lines.py yields 2058 given 2058 lines of code in an open-source library file can't check until a frown turns upside down.
Here is my code:
importsysimportosdefmain():
iflen(sys.argv) !=2:
sys.exit("Too few command-line arguments"iflen(sys.argv) <2else"Too many command-line arguments")
ifnotsys.argv[1].endswith(".py"):
sys.exit("Not a python file")
try:
print(count_lines(sys.argv[1]))
exceptFileNotFoundError:
sys.exit("File does not exist")
defcount_lines(filename):
line_count=0is_doc_string=Falsewithopen(filename, 'r', encoding="utf-8") asfile:
forlineinfile:
line=line.lstrip()
ifnotline:
continue# if line.startswith('"""') or line.startswith("'''"):# is_doc_string = not is_doc_string# continue# if is_doc_string == True:# continue# else:ifnotline.startswith("#"):
line_count+=1returnline_countif__name__=="__main__":
main()
The text was updated successfully, but these errors were encountered:
I'm working on the
lines.py
problem in CS50P, and I encountered an issue with thecheck50
tests. When I include logic to skip docstrings (lines starting with"""
or'''
), thecheck50
test fails for the case where the file contains docstrings. However, if I remove the docstring-checking logic, the tests pass.It gives me the following errors:
:(
lines.py
yields 9 given a file with 9 lines, whitespace, comments, and docstrings expected "9", not "1\n".:|
lines.py
yields 2058 given 2058 lines of code in an open-source library file can't check until a frown turns upside down.Here is my code:
The text was updated successfully, but these errors were encountered: