Skip to content

Instantly share code, notes, and snippets.

@misterhtmlcss
Last active July 20, 2020 02:01
Show Gist options
  • Select an option

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

Select an option

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

Revisions

  1. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -128,5 +128,4 @@ def test_lowercase_list(funcs):
    Reference
    Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tree Press.
    Hunner, T. (2016). "How to loop with indexes in Python". Retrieved from https://treyhunner.com/2016/04/how-to-loop-with-indexes-in-python/
    """
  2. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 22 additions and 24 deletions.
    46 changes: 22 additions & 24 deletions discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -95,40 +95,38 @@ def test_lowercase_list(funcs):
    # **************************
    # OUTPUT
    # **************************
    """
    0** Roger: <function any_lowercase1 at 0x7f983f5b91f0> False
    0** oger: <function any_lowercase1 at 0x7f983f5b91f0> True
    0** rogeR: <function any_lowercase1 at 0x7f983f5b91f0> True

    # 0** Roger: <function any_lowercase1 at 0x7f983f5b91f0> False
    # 0** oger: <function any_lowercase1 at 0x7f983f5b91f0> True
    # 0** rogeR: <function any_lowercase1 at 0x7f983f5b91f0> True


    # 1** Roger: <function any_lowercase2 at 0x7f9840921820> True
    # 1** oger: <function any_lowercase2 at 0x7f9840921820> True
    # 1** rogeR: <function any_lowercase2 at 0x7f9840921820> True

    1** Roger: <function any_lowercase2 at 0x7f9840921820> True
    1** oger: <function any_lowercase2 at 0x7f9840921820> True
    1** rogeR: <function any_lowercase2 at 0x7f9840921820> True

    # 2** Roger: <function any_lowercase3 at 0x7f98409218b0> True
    # 2** oger: <function any_lowercase3 at 0x7f98409218b0> True
    # 2** rogeR: <function any_lowercase3 at 0x7f98409218b0> False

    2** Roger: <function any_lowercase3 at 0x7f98409218b0> True
    2** oger: <function any_lowercase3 at 0x7f98409218b0> True
    2** rogeR: <function any_lowercase3 at 0x7f98409218b0> False

    # 3** Roger: <function any_lowercase4 at 0x7f9840921940> True
    # 3** oger: <function any_lowercase4 at 0x7f9840921940> True
    # 3** rogeR: <function any_lowercase4 at 0x7f9840921940> True

    3** Roger: <function any_lowercase4 at 0x7f9840921940> True
    3** oger: <function any_lowercase4 at 0x7f9840921940> True
    3** rogeR: <function any_lowercase4 at 0x7f9840921940> True

    # 4** Roger: <function any_lowercase5 at 0x7f98409219d0> False
    # 4** oger: <function any_lowercase5 at 0x7f98409219d0> True
    # 4** rogeR: <function any_lowercase5 at 0x7f98409219d0> False

    4** Roger: <function any_lowercase5 at 0x7f98409219d0> False
    4** oger: <function any_lowercase5 at 0x7f98409219d0> True
    4** rogeR: <function any_lowercase5 at 0x7f98409219d0> False

    **************************
    # **************************
    # Reference
    # **************************
    """
    Reference
    **************************
    Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tree Press.
    Hunner, T. (2016). "How to loop with indexes in Python". Retrieved from https://treyhunner.com/2016/04/how-to-loop-with-indexes-in-python/
    """





    """
  3. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 11 additions and 12 deletions.
    23 changes: 11 additions & 12 deletions discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,15 @@
    """
    **************************
    CS1101 - Discussion Unit 5
    **************************
    # **************************
    # CS1101 - Discussion Unit 5
    # **************************

    # **************************
    # Instructions
    # 1. Check whether its argument has any lowercase letters
    # 2. Describe what it actually does when called with a string argument and if it does not correctly check for lowercase letters.
    # 4. Give an example argument that produces incorrect results. (SEE BOTTOM for 3 calls to all functions!)
    # 5. Describe why the result is incorrect. (SEE inline comments)
    # **************************

    **************************
    Instructions
    1. Check whether its argument has any lowercase letters
    2. Describe what it actually does when called with a string argument and if it does not correctly check for lowercase letters.
    4. Give an example argument that produces incorrect results. (SEE BOTTOM for 3 calls to all functions!)
    5. Describe why the result is incorrect. (SEE inline comments)
    **************************
    """


    # **************************
  4. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,7 @@
    **************************
    """


    # **************************
    # Decides on the first letter and breaks the for..in loop once it's True or False
    # Roger == False, because of R,
    @@ -24,6 +25,7 @@ def any_lowercase1(s):
    else:
    return False


    # **************************
    # 'c' is a string. It is passing a string not c the variable, which means it's always true, because 'c' is lowercase.
    def any_lowercase2(s):
    @@ -52,6 +54,7 @@ def any_lowercase4(s):
    flag = flag or c.islower()
    return flag


    # **************************
    # Will check if string has an uppercase and when True, then break the for..in loop with a False.
    def any_lowercase5(s):
  5. misterhtmlcss revised this gist Jul 20, 2020. No changes.
  6. misterhtmlcss revised this gist Jul 20, 2020. No changes.
  7. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -85,10 +85,11 @@ def test_lowercase_list(funcs):

    # This function iterates over all the functions from list_funcs
    test_lowercase_list(list_funcs)


    # **************************
    # **************************
    # **************************


    # **************************
    # OUTPUT
    # **************************
  8. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -90,10 +90,9 @@ def test_lowercase_list(funcs):
    # **************************
    # **************************
    # **************************
    # OUTPUT
    # **************************
    """
    **************************
    OUTPUT
    **************************
    0** Roger: <function any_lowercase1 at 0x7f983f5b91f0> False
    0** oger: <function any_lowercase1 at 0x7f983f5b91f0> True
    0** rogeR: <function any_lowercase1 at 0x7f983f5b91f0> True
  9. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -87,6 +87,9 @@ def test_lowercase_list(funcs):
    test_lowercase_list(list_funcs)


    # **************************
    # **************************
    # **************************
    """
    **************************
    OUTPUT
  10. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -68,7 +68,7 @@ def any_lowercase5(s):

    # **************************
    # Program manager
    # Runs all the functions with the same print series
    # Runs all the functions with the test strings in series and prints them.
    # **************************
    def test_lowercase_list(funcs):
    #i when, func what is called, func('xxx') results printed
  11. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -63,6 +63,7 @@ def any_lowercase5(s):
    return True
    # **************************
    # **************************
    # **************************


    # **************************
  12. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -61,9 +61,14 @@ def any_lowercase5(s):
    return False
    # All iterations succeed without a return and then the function exits the for..in and returns True.
    return True
    # **************************
    # **************************


    # **************************
    # Program manager
    # Runs all the functions with the same print series
    # **************************
    def test_lowercase_list(funcs):
    #i when, func what is called, func('xxx') results printed
    for i, func in enumerate(funcs): # (Hunner, T., 2016)
    @@ -73,6 +78,7 @@ def test_lowercase_list(funcs):
    print(f'{i}** rogeR:', func, func('rogeR'))
    print('\n')

    # **************************
    # list of functions above
    list_funcs = [any_lowercase1, any_lowercase2, any_lowercase3, any_lowercase4, any_lowercase5]

  13. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 14 additions and 7 deletions.
    21 changes: 14 additions & 7 deletions discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,8 @@
    **************************
    """

    # 1: Decides on the first letter and breaks the for..in loop once it's True or False
    # **************************
    # Decides on the first letter and breaks the for..in loop once it's True or False
    # Roger == False, because of R,
    # oger == True, because of o
    # ogeR == True, because of o; doesn't keep looking.
    @@ -23,7 +24,8 @@ def any_lowercase1(s):
    else:
    return False

    # 2: 'c' is a string. It is passing a string not c the variable, which means it's always true, because 'c' is lowercase.
    # **************************
    # 'c' is a string. It is passing a string not c the variable, which means it's always true, because 'c' is lowercase.
    def any_lowercase2(s):
    for c in s:
    # Lowercase is true every time.
    @@ -32,21 +34,26 @@ def any_lowercase2(s):
    else:
    return 'False'

    # 3a. 'flag' (inner variable) is declared inside the scope of the for..in loop and it's scope doesn't extend to the parent scope of the function.
    # 3b. name 'flag' (outer variable) is not defined. It's irrelevant.

    # **************************
    # A. 'flag' (inner variable) is declared inside the scope of the for..in loop and it's scope doesn't extend to the parent scope of the function.
    # B. name 'flag' (outer variable) is not defined. It's irrelevant.
    def any_lowercase3(s):
    for c in s:
    flag = c.islower()
    return flag

    # 4: Once the `flag` is found to be True it can't be reassigned. First 'truth' means all are True.

    # **************************
    # Once the `flag` is found to be True it can't be reassigned. First 'truth' means all are True.
    def any_lowercase4(s):
    flag = False
    for c in s:
    flag = flag or c.islower()
    return flag

    # 5 Will check if string has an uppercase and when True, then break the for..in loop with a False.
    # **************************
    # Will check if string has an uppercase and when True, then break the for..in loop with a False.
    def any_lowercase5(s):
    for c in s:
    # Iterates continuously inside this loop until the return False on any single uppercase
    @@ -55,7 +62,7 @@ def any_lowercase5(s):
    # All iterations succeed without a return and then the function exits the for..in and returns True.
    return True


    # **************************
    # Runs all the functions with the same print series
    def test_lowercase_list(funcs):
    #i when, func what is called, func('xxx') results printed
  14. misterhtmlcss revised this gist Jul 20, 2020. No changes.
  15. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -3,10 +3,13 @@
    CS1101 - Discussion Unit 5
    **************************
    **************************
    Instructions
    1. Check whether its argument has any lowercase letters
    2. Describe what it actually does when called with a string argument and if it does not correctly check for lowercase letters.
    4. Give an example argument that produces incorrect results. (SEE BOTTOM for 3 calls to all functions!)
    5. Describe why the result is incorrect. (SEE inline comments)
    **************************
    """

    # 1: Decides on the first letter and breaks the for..in loop once it's True or False
    @@ -71,8 +74,9 @@ def test_lowercase_list(funcs):


    """
    **************************
    OUTPUT
    **************************
    0** Roger: <function any_lowercase1 at 0x7f983f5b91f0> False
    0** oger: <function any_lowercase1 at 0x7f983f5b91f0> True
    0** rogeR: <function any_lowercase1 at 0x7f983f5b91f0> True
    @@ -97,8 +101,9 @@ def test_lowercase_list(funcs):
    4** oger: <function any_lowercase5 at 0x7f98409219d0> True
    4** rogeR: <function any_lowercase5 at 0x7f98409219d0> False
    **************************
    Reference
    **************************
    Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tree Press.
    Hunner, T. (2016). "How to loop with indexes in Python". Retrieved from https://treyhunner.com/2016/04/how-to-loop-with-indexes-in-python/
  16. misterhtmlcss revised this gist Jul 20, 2020. No changes.
  17. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,8 @@
    """
    **************************
    CS1101 - Discussion Unit 5
    **************************
    1. Check whether its argument has any lowercase letters
    2. Describe what it actually does when called with a string argument and if it does not correctly check for lowercase letters.
    4. Give an example argument that produces incorrect results. (SEE BOTTOM for 3 calls to all functions!)
  18. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -92,12 +92,15 @@ def test_lowercase_list(funcs):
    4** Roger: <function any_lowercase5 at 0x7f98409219d0> False
    4** oger: <function any_lowercase5 at 0x7f98409219d0> True
    4** rogeR: <function any_lowercase5 at 0x7f98409219d0> False
    Reference
    Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tree Press.
    Hunner, T. (2016). "How to loop with indexes in Python". Retrieved from https://treyhunner.com/2016/04/how-to-loop-with-indexes-in-python/
    """



    # Reference
    # Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tree Press.
    # Hunner, T. (2016). "How to loop with indexes in Python". Retrieved from https://treyhunner.com/2016/04/how-to-loop-with-indexes-in-python/


  19. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -65,7 +65,10 @@ def test_lowercase_list(funcs):
    # This function iterates over all the functions from list_funcs
    test_lowercase_list(list_funcs)


    """
    OUTPUT
    0** Roger: <function any_lowercase1 at 0x7f983f5b91f0> False
    0** oger: <function any_lowercase1 at 0x7f983f5b91f0> True
    0** rogeR: <function any_lowercase1 at 0x7f983f5b91f0> True
  20. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 29 additions and 1 deletion.
    30 changes: 29 additions & 1 deletion discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -65,8 +65,36 @@ def test_lowercase_list(funcs):
    # This function iterates over all the functions from list_funcs
    test_lowercase_list(list_funcs)

    """
    0** Roger: <function any_lowercase1 at 0x7f983f5b91f0> False
    0** oger: <function any_lowercase1 at 0x7f983f5b91f0> True
    0** rogeR: <function any_lowercase1 at 0x7f983f5b91f0> True
    1** Roger: <function any_lowercase2 at 0x7f9840921820> True
    1** oger: <function any_lowercase2 at 0x7f9840921820> True
    1** rogeR: <function any_lowercase2 at 0x7f9840921820> True
    2** Roger: <function any_lowercase3 at 0x7f98409218b0> True
    2** oger: <function any_lowercase3 at 0x7f98409218b0> True
    2** rogeR: <function any_lowercase3 at 0x7f98409218b0> False
    3** Roger: <function any_lowercase4 at 0x7f9840921940> True
    3** oger: <function any_lowercase4 at 0x7f9840921940> True
    3** rogeR: <function any_lowercase4 at 0x7f9840921940> True
    4** Roger: <function any_lowercase5 at 0x7f98409219d0> False
    4** oger: <function any_lowercase5 at 0x7f98409219d0> True
    4** rogeR: <function any_lowercase5 at 0x7f98409219d0> False
    """



    # Reference
    # Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tree Press.
    # Hunner, T. (2016). "How to loop with indexes in Python". Retrieved from https://treyhunner.com/2016/04/how-to-loop-with-indexes-in-python/
    # Hunner, T. (2016). "How to loop with indexes in Python". Retrieved from https://treyhunner.com/2016/04/how-to-loop-with-indexes-in-python/


  21. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    1. Check whether its argument has any lowercase letters
    2. Describe what it actually does when called with a string argument and if it does not correctly check for lowercase letters.
    4. Give an example argument that produces incorrect results. (SEE BOTTOM for 3 calls to all functions!)
    5. Describe why the result is incorrect. (SEE INLINE COMMENTS)
    5. Describe why the result is incorrect. (SEE inline comments)
    """

    # 1: Decides on the first letter and breaks the for..in loop once it's True or False
  22. misterhtmlcss revised this gist Jul 20, 2020. No changes.
  23. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    1. Check whether its argument has any lowercase letters
    2. Describe what it actually does when called with a string argument and if it does not correctly check for lowercase letters.
    4. Give an example argument that produces incorrect results. (SEE BOTTOM for 3 calls to all functions!)
    5. Describe why the result is incorrect.
    5. Describe why the result is incorrect. (SEE INLINE COMMENTS)
    """

    # 1: Decides on the first letter and breaks the for..in loop once it's True or False
  24. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -63,7 +63,7 @@ def test_lowercase_list(funcs):
    list_funcs = [any_lowercase1, any_lowercase2, any_lowercase3, any_lowercase4, any_lowercase5]

    # This function iterates over all the functions from list_funcs
    print('funcs working? ', test_lowercase_list(list_funcs))
    test_lowercase_list(list_funcs)



  25. misterhtmlcss revised this gist Jul 20, 2020. No changes.
  26. misterhtmlcss revised this gist Jul 20, 2020. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,8 @@
    """
    1. Check whether its argument has any lowercase letters
    2. describe what it actually does when called with a string argument
    3. If it does not correctly check for lowercase letters, give an example argument that produces incorrect results, and describe why the result is incorrect.
    2. Describe what it actually does when called with a string argument and if it does not correctly check for lowercase letters.
    4. Give an example argument that produces incorrect results. (SEE BOTTOM for 3 calls to all functions!)
    5. Describe why the result is incorrect.
    """

    # 1: Decides on the first letter and breaks the for..in loop once it's True or False
  27. misterhtmlcss created this gist Jul 20, 2020.
    71 changes: 71 additions & 0 deletions discussion-unit-5.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,71 @@
    """
    1. Check whether its argument has any lowercase letters
    2. describe what it actually does when called with a string argument
    3. If it does not correctly check for lowercase letters, give an example argument that produces incorrect results, and describe why the result is incorrect.
    """

    # 1: Decides on the first letter and breaks the for..in loop once it's True or False
    # Roger == False, because of R,
    # oger == True, because of o
    # ogeR == True, because of o; doesn't keep looking.
    def any_lowercase1(s):
    for c in s:
    if c.islower():
    return True
    else:
    return False

    # 2: 'c' is a string. It is passing a string not c the variable, which means it's always true, because 'c' is lowercase.
    def any_lowercase2(s):
    for c in s:
    # Lowercase is true every time.
    if 'c'.islower():
    return 'True'
    else:
    return 'False'

    # 3a. 'flag' (inner variable) is declared inside the scope of the for..in loop and it's scope doesn't extend to the parent scope of the function.
    # 3b. name 'flag' (outer variable) is not defined. It's irrelevant.
    def any_lowercase3(s):
    for c in s:
    flag = c.islower()
    return flag

    # 4: Once the `flag` is found to be True it can't be reassigned. First 'truth' means all are True.
    def any_lowercase4(s):
    flag = False
    for c in s:
    flag = flag or c.islower()
    return flag

    # 5 Will check if string has an uppercase and when True, then break the for..in loop with a False.
    def any_lowercase5(s):
    for c in s:
    # Iterates continuously inside this loop until the return False on any single uppercase
    if not c.islower():
    return False
    # All iterations succeed without a return and then the function exits the for..in and returns True.
    return True


    # Runs all the functions with the same print series
    def test_lowercase_list(funcs):
    #i when, func what is called, func('xxx') results printed
    for i, func in enumerate(funcs): # (Hunner, T., 2016)
    # prints index number with string test, function and function call result.
    print(f'{i}** Roger:', func, func('Roger'))
    print(f'{i}** oger:', func, func('ogerc'))
    print(f'{i}** rogeR:', func, func('rogeR'))
    print('\n')

    # list of functions above
    list_funcs = [any_lowercase1, any_lowercase2, any_lowercase3, any_lowercase4, any_lowercase5]

    # This function iterates over all the functions from list_funcs
    print('funcs working? ', test_lowercase_list(list_funcs))



    # Reference
    # Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tree Press.
    # Hunner, T. (2016). "How to loop with indexes in Python". Retrieved from https://treyhunner.com/2016/04/how-to-loop-with-indexes-in-python/