-
Notifications
You must be signed in to change notification settings - Fork 25
Formative feedback #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a3e6896
1c255d3
f4aa85e
6ca8ad9
2d36701
93e55da
8123c7e
a78f181
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,19 +3,58 @@ | |
|
|
||
| TASK_FILE = ".tasks.txt" | ||
|
|
||
|
|
||
| def add_task(task): | ||
| """Function: add_task | ||
|
|
||
| Input - a task to add to the list | ||
| Return - nothing | ||
| """ | ||
| #Open the file in append mode to add a new task to the end of the exisitng list | ||
| with open(TASK_FILE, "a", encoding="utf-8") as file: | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perfect |
||
| #Write the task followed by a newline character so the task appears on a new line | ||
| file.write(task +"\n") | ||
|
|
||
| #Listing all tasks within the task file | ||
| def list_tasks(): | ||
| return | ||
|
|
||
| with open(TASK_FILE, "r", encoding="utf-8") as file: | ||
| tasks = file.readlines() | ||
| counter = 1 | ||
| output_string = "" | ||
| for task in tasks: | ||
| output_string = output_string + str(counter) + ". " +task | ||
| counter = counter + 1 | ||
| #Code from Gemini | ||
| my_string = '1. Item 1\n2. Item 2\n3. Item 3\n4. Item 4\n5. Item 5\n' | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. almost; you have output_string correct, so this line should be removed and the line below is output_string[:-1], or better yet output_string.rstrip() |
||
| modified_string = my_string[:-1] | ||
| print(modified_string) | ||
|
|
||
| return modified_string | ||
|
|
||
|
|
||
| def remove_task(index): | ||
| return | ||
| """Function: remove_task | ||
|
|
||
| Input - a task to add to the list | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Super! Some errors in the syntax here, with a random else. The if accompanying this has gone awol... |
||
| Return - nothing | ||
| """ | ||
| #Read all lines within the task file | ||
| with open(TASK_FILE, 'r', encoding='utf-8') as file: | ||
| lines = file.readlines() | ||
|
|
||
| #Check that the line to remove is valid | ||
| if 1 <= index <= len(lines): | ||
| lines.pop(index - 1) | ||
|
|
||
| #Update the list and add it back to the original file | ||
| with open(TASK_FILE, 'w', encoding='utf-8') as file: | ||
| file.writelines(lines) | ||
|
|
||
|
|
||
| print ('Task removed.') | ||
| else: | ||
| print('Invalid task number.') | ||
|
|
||
| return | ||
|
|
||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description="Command-line Todo List") | ||
|
|
@@ -42,7 +81,10 @@ def main(): | |
| tasks = list_tasks() | ||
| print(tasks) | ||
| elif args.remove: | ||
| remove_task(int(args.remove)) | ||
| try: remove_task(int(args.remove)) | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good attempt at this! |
||
| #Code from Gemini | ||
| except ValueError: | ||
| print("Error: Please provide a number for the task index to remove.") | ||
| else: | ||
| parser.print_help() | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try not to add additional whitespace in a function which is not the subject of the commit. Keep commits clean and use git diff to see what will change in each file.