Skip to content

Instantly share code, notes, and snippets.

@misterhtmlcss
Last active December 9, 2021 02:55
Show Gist options
  • Select an option

  • Save misterhtmlcss/4db08e281c4800b6b2c3478d83ddab4a to your computer and use it in GitHub Desktop.

Select an option

Save misterhtmlcss/4db08e281c4800b6b2c3478d83ddab4a to your computer and use it in GitHub Desktop.

Revisions

  1. misterhtmlcss revised this gist Jul 15, 2020. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions discussion-unit4.py
    Original file line number Diff line number Diff line change
    @@ -44,9 +44,10 @@ def add_todo(task, isDone=False):
    return "Empty a todo."

    # Precondition ------ problem; this is at the argument stage and before it's passed into the parameters
    add_todo(True, "Tomatos")

    add_todo("Lettuce", False)

    add_todo("Tomatos", True)

    # Postcondition ------ Function call sends string argument, but 'if' condition doesn't catch this error and passes the data to the store. See how the store has an empty string now?
    add_todo("", False)
    @@ -84,14 +85,16 @@ def todo_lists(fn, task, label, current_list):
    todo_lists(add_todo, "M&Ms", "Grocery List", False )
    print("\n\n")

    # ---------------- Start of assignment silliness ----------------

    # **************************
    # *************** Start of assignment silliness ***************
    # Interested in more? I had some fun for a bit. Wanted to try push what I'm learning through class, the book and elsewhere.
    # The below is way way off base, but it was fun and I just went for it. I left ALL the prints in there, so I'd recommend removing them and reading it and then adding them back in and reading and watching what happens...
    # **************************

    def run_program(current_list, count=0):
    counter = int(count)
    if counter <= 0:
    print('lists', store)
    print('done running the program')
    return
    else:
  2. misterhtmlcss revised this gist Jul 12, 2020. 1 changed file with 14 additions and 18 deletions.
    32 changes: 14 additions & 18 deletions discussion-unit4.py
    Original file line number Diff line number Diff line change
    @@ -4,28 +4,31 @@
    # ✓ Define "precondition" and "postcondition" as part of your description. (First two paragraphs)
    # ✓ Describe each possibility in your own words. (All three paragraphs)

    # A precondtion is a problem before the function’s arguments are passed into the parameters (Downey, A. 2015). Are there arguments being passed? Sometimes a function is called a long ways away from where it’s defined. With languages like Python it’s often critical to name parameters effectively so that the correct arguments are passed. This can be as simple as missing a type e.g. ‘5’ instead of 5.
    # A postcondition is a problem that follows from the point immediately following the arguments being passed (Downey, A. 2015). A really simple example could be `function (a, b) { b -a }`. No matter the language we can all see how it’s unlikely that a human mind would order the parameters as a followed by b and then have them flipped within the function body. Another example could be variable mutation is like a disease. Sometimes you instantiate a variable a particular way within a function, but it is mutated without your knowledge and this impacts a possibly critical sequence of events. A set of examples of this can be found at Python Tips (2017)
    # Another problem is the ‘moment’ of computation return. The moment when we use the value created from the function can trip people up, especially new programmers that are used to using print statements. Often new programmers will have a print statement where a return statement is necessary. Without a return statement there is no value being returned and this can lead to a lot of confusion since a return statement doesn’t give any signal on a REPL program. Additionally a huge weak point and I saw this today was a failure to use returns within an if/else conditional workflow. Due to the missing return the function was also applying a final statement on the last line that wasn’t meant to be called. In fact the developer left this statement only as a reminder for something else to do, but it was in fact messing up the rest of his program.
    # A precondtion is a problem before the function’s arguments are passed into the parameters (Downey, A. 2015). Are there arguments being passed? Sometimes a function is called a long ways away from where it’s defined. With languages like Python it’s often critical to name parameters effectively so that the correct arguments are passed. This can be as simple as missing a type e.g. ‘5’ instead of 5.

    # A postcondition is a problem that follows from the point immediately following the arguments being passed (Downey, A. 2015). A really simple example could be `function (a, b) { b -a }`. No matter the language we can all see how it’s unlikely that a human mind would order the parameters as a followed by b and then have them flipped within the function body. Another example could be variable mutation is like a disease. Sometimes you instantiate a variable a particular way within a function, but it is mutated without your knowledge and this impacts a possibly critical sequence of events. A set of examples of this can be found at Python Tips (2017)

    # Another problem is the ‘moment’ of computation return. The moment when we use the value created from the function can trip people up, especially new programmers that are used to using print statements. Often new programmers will have a print statement where a return statement is necessary. Without a return statement there is no value being returned and this can lead to a lot of confusion since a return statement doesn’t give any signal on a REPL program. Additionally a huge weak point and I saw this today was a failure to use returns within an if/else conditional workflow. Due to the missing return the function was also applying a final statement on the last line that wasn’t meant to be called. In fact the developer left this statement only as a reminder for something else to do, but it was in fact messing up the rest of his program.


    # Reference
    # Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press.
    # Ullah, M. Y. Khalid (2017). Python Tips. Retrieved from https://book.pythontips.com/en/latest/mutation.html

    # FOR SPACING ---- Ignore me
    print("\n")
    print("\n\n")
    # FOR SPACING ---- Ignore me


    # ✓ Create your own example of each possibility in Python code. List the code for each example, along with sample output from trying to run it.

    # Store all the todos and the lists they belong to in the Store
    store={}
    # List (Python) of Dictionaries or Objects (JavaScript terminology)
    todos=[]
    # Keeps track of whichever list the user is currently adding to.
    current_list=""

    # Task should be a string and isDone is a boolean defaulting to false.
    def add_todo(task, isDone=False):

    # Is task a String? Postcondition ------ Function call sends string argument, but 'if' condition doesn't catch this error and passes the data to the store. See how the store has an empty string now?
    # Is task a String
    if isinstance(task, str):
    # String and Bool in a Dictionary (Python) / Object (JavaScript)
    todo={ 'task': task, 'complete': isDone}
    @@ -41,7 +44,7 @@ def add_todo(task, isDone=False):
    return "Empty a todo."

    # Precondition ------ problem; this is at the argument stage and before it's passed into the parameters
    add_todo(False, "Lettuce")
    add_todo("Lettuce", False)

    add_todo("Tomatos", True)

    @@ -105,11 +108,4 @@ def run_program(current_list, count=0):
    run_program(current_list, input("Let's create some todo lists today!! How many would you like to create? "))
    # ---------------- End of assignment silliness ----------------

    # This is the entrypoint function. This is called on file run. When run it prints all the data and in the order required by the instructions.


    # Reference
    # Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press.
    # Ullah, M. Y. Khalid (2017). Python Tips. Retrieved from https://book.pythontips.com/en/latest/mutation.html
    # Paulson, O. (n.d.). Scrimba. Retrieved from https://scrimba.com/course/gpython
    # Parewa Labs Pvt (n.d.). Retrieved from https://www.programiz.com/python-programming
    # This is the entrypoint function. This is called on file run. When run it prints all the data and in the order required by the instructions.
  3. misterhtmlcss revised this gist Jul 12, 2020. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion discussion-unit4.py
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,6 @@

    # Store all the todos and the lists they belong to in the Store
    store={}

    # List (Python) of Dictionaries or Objects (JavaScript terminology)
    todos=[]
    # Keeps track of whichever list the user is currently adding to.
  4. misterhtmlcss revised this gist Jul 12, 2020. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions discussion-unit4.py
    Original file line number Diff line number Diff line change
    @@ -5,21 +5,22 @@
    # ✓ Describe each possibility in your own words. (All three paragraphs)

    # A precondtion is a problem before the function’s arguments are passed into the parameters (Downey, A. 2015). Are there arguments being passed? Sometimes a function is called a long ways away from where it’s defined. With languages like Python it’s often critical to name parameters effectively so that the correct arguments are passed. This can be as simple as missing a type e.g. ‘5’ instead of 5.

    # A postcondition is a problem that follows from the point immediately following the arguments being passed (Downey, A. 2015). A really simple example could be `function (a, b) { b -a }`. No matter the language we can all see how it’s unlikely that a human mind would order the parameters as a followed by b and then have them flipped within the function body. Another example could be variable mutation is like a disease. Sometimes you instantiate a variable a particular way within a function, but it is mutated without your knowledge and this impacts a possibly critical sequence of events. A set of examples of this can be found at Python Tips (2017)

    # Another problem is the ‘moment’ of computation return. The moment when we use the value created from the function can trip people up, especially new programmers that are used to using print statements. Often new programmers will have a print statement where a return statement is necessary. Without a return statement there is no value being returned and this can lead to a lot of confusion since a return statement doesn’t give any signal on a REPL program. Additionally a huge weak point and I saw this today was a failure to use returns within an if/else conditional workflow. Due to the missing return the function was also applying a final statement on the last line that wasn’t meant to be called. In fact the developer left this statement only as a reminder for something else to do, but it was in fact messing up the rest of his program.

    # FOR SPACING ---- Ignore me
    print("\n")
    # FOR SPACING ---- Ignore me


    # ✓ Create your own example of each possibility in Python code. List the code for each example, along with sample output from trying to run it.

    # Store all the todos and the lists they belong to in the Store
    store={}

    # List (Python) of Dictionaries or Objects (JavaScript terminology)
    todos=[]
    # Keeps track of whichever list the user is currently adding to.
    current_list=""

    # Task should be a string and isDone is a boolean defaulting to false.
  5. misterhtmlcss revised this gist Jul 12, 2020. 1 changed file with 9 additions and 7 deletions.
    16 changes: 9 additions & 7 deletions discussion-unit4.py
    Original file line number Diff line number Diff line change
    @@ -10,13 +10,8 @@

    # Another problem is the ‘moment’ of computation return. The moment when we use the value created from the function can trip people up, especially new programmers that are used to using print statements. Often new programmers will have a print statement where a return statement is necessary. Without a return statement there is no value being returned and this can lead to a lot of confusion since a return statement doesn’t give any signal on a REPL program. Additionally a huge weak point and I saw this today was a failure to use returns within an if/else conditional workflow. Due to the missing return the function was also applying a final statement on the last line that wasn’t meant to be called. In fact the developer left this statement only as a reminder for something else to do, but it was in fact messing up the rest of his program.


    # Reference
    # Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press.
    # Ullah, M. Y. Khalid (2017). Python Tips. Retrieved from https://book.pythontips.com/en/latest/mutation.html

    # FOR SPACING ---- Ignore me
    print("\n\n")
    print("\n")
    # FOR SPACING ---- Ignore me

    # ✓ Create your own example of each possibility in Python code. List the code for each example, along with sample output from trying to run it.
    @@ -110,4 +105,11 @@ def run_program(current_list, count=0):
    run_program(current_list, input("Let's create some todo lists today!! How many would you like to create? "))
    # ---------------- End of assignment silliness ----------------

    # This is the entrypoint function. This is called on file run. When run it prints all the data and in the order required by the instructions.
    # This is the entrypoint function. This is called on file run. When run it prints all the data and in the order required by the instructions.


    # Reference
    # Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press.
    # Ullah, M. Y. Khalid (2017). Python Tips. Retrieved from https://book.pythontips.com/en/latest/mutation.html
    # Paulson, O. (n.d.). Scrimba. Retrieved from https://scrimba.com/course/gpython
    # Parewa Labs Pvt (n.d.). Retrieved from https://www.programiz.com/python-programming
  6. misterhtmlcss revised this gist Jul 12, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion discussion-unit4.py
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,7 @@ def add_todo(task, isDone=False):
    return "Empty a todo."

    # Precondition ------ problem; this is at the argument stage and before it's passed into the parameters
    add_todo("Lettuce", False)
    add_todo(False, "Lettuce")

    add_todo("Tomatos", True)

  7. misterhtmlcss revised this gist Jul 12, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion discussion-unit4.py
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,8 @@

    # Task should be a string and isDone is a boolean defaulting to false.
    def add_todo(task, isDone=False):
    # Is task a String

    # Is task a String? Postcondition ------ Function call sends string argument, but 'if' condition doesn't catch this error and passes the data to the store. See how the store has an empty string now?
    if isinstance(task, str):
    # String and Bool in a Dictionary (Python) / Object (JavaScript)
    todo={ 'task': task, 'complete': isDone}
  8. misterhtmlcss revised this gist Jul 12, 2020. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions discussion-unit4.py
    Original file line number Diff line number Diff line change
    @@ -4,11 +4,11 @@
    # ✓ Define "precondition" and "postcondition" as part of your description. (First two paragraphs)
    # ✓ Describe each possibility in your own words. (All three paragraphs)

    # A precondtion is a problem before the function’s arguments are passed into the parameters (Downey, A. 2015). Are there arguments being passed? Sometimes a function is called a long ways away from where it’s defined. With languages like Python it’s often critical to name parameters effectively so that the correct arguments are passed. This can be as simple as missing a type e.g. ‘5’ instead of 5.
    # A precondtion is a problem before the function’s arguments are passed into the parameters (Downey, A. 2015). Are there arguments being passed? Sometimes a function is called a long ways away from where it’s defined. With languages like Python it’s often critical to name parameters effectively so that the correct arguments are passed. This can be as simple as missing a type e.g. ‘5’ instead of 5.

    # A postcondition is a problem that follows from the point immediately following the arguments being passed (Downey, A. 2015). A really simple example could be `function (a, b) { b -a }`. No matter the language we can all see how it’s unlikely that a human mind would order the parameters as a followed by b and then have them flipped within the function body. Another example could be variable mutation is like a disease. Sometimes you instantiate a variable a particular way within a function, but it is mutated without your knowledge and this impacts a possibly critical sequence of events. A set of examples of this can be found at Python Tips (2017)
    # A postcondition is a problem that follows from the point immediately following the arguments being passed (Downey, A. 2015). A really simple example could be `function (a, b) { b -a }`. No matter the language we can all see how it’s unlikely that a human mind would order the parameters as a followed by b and then have them flipped within the function body. Another example could be variable mutation is like a disease. Sometimes you instantiate a variable a particular way within a function, but it is mutated without your knowledge and this impacts a possibly critical sequence of events. A set of examples of this can be found at Python Tips (2017)

    # Another problem is the ‘moment’ of computation return. The moment when we use the value created from the function can trip people up, especially new programmers that are used to using print statements. Often new programmers will have a print statement where a return statement is necessary. Without a return statement there is no value being returned and this can lead to a lot of confusion since a return statement doesn’t give any signal on a REPL program. Additionally a huge weak point and I saw this today was a failure to use returns within an if/else conditional workflow. Due to the missing return the function was also applying a final statement on the last line that wasn’t meant to be called. In fact the developer left this statement only as a reminder for something else to do, but it was in fact messing up the rest of his program.
    # Another problem is the ‘moment’ of computation return. The moment when we use the value created from the function can trip people up, especially new programmers that are used to using print statements. Often new programmers will have a print statement where a return statement is necessary. Without a return statement there is no value being returned and this can lead to a lot of confusion since a return statement doesn’t give any signal on a REPL program. Additionally a huge weak point and I saw this today was a failure to use returns within an if/else conditional workflow. Due to the missing return the function was also applying a final statement on the last line that wasn’t meant to be called. In fact the developer left this statement only as a reminder for something else to do, but it was in fact messing up the rest of his program.


    # Reference
  9. misterhtmlcss revised this gist Jul 12, 2020. No changes.
  10. misterhtmlcss created this gist Jul 12, 2020.
    112 changes: 112 additions & 0 deletions discussion-unit4.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,112 @@
    # CS1101 - Discussion Forum Unit 4
    # Section 6.9 of your textbook ("Debugging") lists three possibilities to consider if a function is not working.

    # ✓ Define "precondition" and "postcondition" as part of your description. (First two paragraphs)
    # ✓ Describe each possibility in your own words. (All three paragraphs)

    # A precondtion is a problem before the function’s arguments are passed into the parameters (Downey, A. 2015). Are there arguments being passed? Sometimes a function is called a long ways away from where it’s defined. With languages like Python it’s often critical to name parameters effectively so that the correct arguments are passed. This can be as simple as missing a type e.g. ‘5’ instead of 5.

    # A postcondition is a problem that follows from the point immediately following the arguments being passed (Downey, A. 2015). A really simple example could be `function (a, b) { b -a }`. No matter the language we can all see how it’s unlikely that a human mind would order the parameters as a followed by b and then have them flipped within the function body. Another example could be variable mutation is like a disease. Sometimes you instantiate a variable a particular way within a function, but it is mutated without your knowledge and this impacts a possibly critical sequence of events. A set of examples of this can be found at Python Tips (2017)

    # Another problem is the ‘moment’ of computation return. The moment when we use the value created from the function can trip people up, especially new programmers that are used to using print statements. Often new programmers will have a print statement where a return statement is necessary. Without a return statement there is no value being returned and this can lead to a lot of confusion since a return statement doesn’t give any signal on a REPL program. Additionally a huge weak point and I saw this today was a failure to use returns within an if/else conditional workflow. Due to the missing return the function was also applying a final statement on the last line that wasn’t meant to be called. In fact the developer left this statement only as a reminder for something else to do, but it was in fact messing up the rest of his program.


    # Reference
    # Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press.
    # Ullah, M. Y. Khalid (2017). Python Tips. Retrieved from https://book.pythontips.com/en/latest/mutation.html

    # FOR SPACING ---- Ignore me
    print("\n\n")
    # FOR SPACING ---- Ignore me

    # ✓ Create your own example of each possibility in Python code. List the code for each example, along with sample output from trying to run it.

    store={}

    # List (Python) of Dictionaries or Objects (JavaScript terminology)
    todos=[]
    current_list=""

    # Task should be a string and isDone is a boolean defaulting to false.
    def add_todo(task, isDone=False):
    # Is task a String
    if isinstance(task, str):
    # String and Bool in a Dictionary (Python) / Object (JavaScript)
    todo={ 'task': task, 'complete': isDone}
    # Dictionary appended to 'todos' List
    todos.append(todo)
    # Test the todos was updated
    # print('todos1', todos)
    # Return value of todos
    return todos
    else:
    # Test out put on failure
    # print("Empty a todo.", task)
    return "Empty a todo."

    # Precondition ------ problem; this is at the argument stage and before it's passed into the parameters
    add_todo("Lettuce", False)

    add_todo("Tomatos", True)

    # Postcondition ------ Function call sends string argument, but 'if' condition doesn't catch this error and passes the data to the store. See how the store has an empty string now?
    add_todo("", False)

    # Test global has been correctly mutated according to plan.
    print("todos", todos, "\n\n")


    # ---------------- I wrote a bunch of prints because of the below stretch..I left them in to see what it took for me to get it working ----------------
    # This function takes a list of task that the user generates and then addes them to a specific label e.g. Recipies, Groceries
    # fn=function, task=string, isDone=Boolean, label=string
    def todo_lists(fn, task, label, current_list):
    # print('first current list', current_list)
    if current_list == label:
    store[label] = fn(task)
    # print('store', store)
    # Remove any of these current_lists and most of the functionality crashes, but without the user knowing immediately.
    return current_list
    elif not current_list:
    current_list = label
    # print('current list', current_list)
    store[label] = fn(task)
    # print('store', store)
    # Remove any of these current_lists and most of the functionality crashes, but without the user knowing immediately.
    return current_list
    else:
    current_list = label
    todos.clear()
    # print("todos cleared", todos)
    store[label] = fn(task)
    # print('store', store)
    # Remove any of these current_lists and most of the functionality crashes, but without the user knowing immediately.
    return current_list

    todo_lists(add_todo, "M&Ms", "Grocery List", False )
    print("\n\n")

    # ---------------- Start of assignment silliness ----------------

    # Interested in more? I had some fun for a bit. Wanted to try push what I'm learning through class, the book and elsewhere.
    # The below is way way off base, but it was fun and I just went for it. I left ALL the prints in there, so I'd recommend removing them and reading it and then adding them back in and reading and watching what happens...

    def run_program(current_list, count=0):
    counter = int(count)
    if counter <= 0:
    print('done running the program')
    return
    else:
    my_todo=input("What do you need today? ")
    print("\n")
    my_label=input("What list would you like to add this to? ")
    print("\n")
    prev_list=todo_lists(add_todo, my_todo, my_label, current_list)
    # print('prev_list', prev_list)
    run_program(prev_list, counter-1)


    if __name__ == "__main__":
    run_program(current_list, input("Let's create some todo lists today!! How many would you like to create? "))
    # ---------------- End of assignment silliness ----------------

    # This is the entrypoint function. This is called on file run. When run it prints all the data and in the order required by the instructions.