Skip to content

21 make errors example into a function#56

Merged
Scottan merged 8 commits intomainfrom
21-make-errors-example-into-a-function
Apr 13, 2026
Merged

21 make errors example into a function#56
Scottan merged 8 commits intomainfrom
21-make-errors-example-into-a-function

Conversation

@Scottan
Copy link
Copy Markdown
Collaborator

@Scottan Scottan commented Nov 14, 2025

I've made it into a function and updated some of the text

Any thoughts on replacing:

def check_value(val):
    if val>0 and val<10:
        print('Value: ', val, 'is a digit.')
    elif val==0:
        print('Value ', val, 'is nul')
    else:
        print('Value: ', val, 'is a number.')

with:

def check_sign(val):
    if val == 0:
        print('Value: ', val, 'is zero.')
    elif val > 0:
        print('Value ', val, 'is positive')
    else:
        print('Value: ', val, 'is negative.')

I personally think it's a clearer and less distracting test, see #21.

I also wonder if we should add a note saying it is usually a good idea to put the try / except statements inside the function, but we are going to leave them outside the function for these examples

@Scottan Scottan linked an issue Nov 14, 2025 that may be closed by this pull request
@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 14, 2025

Thank you!

Thank you for your pull request 😃

🤖 This automated message can help you check the rendered files in your submission for clarity. If you have any questions, please feel free to open an issue in {sandpaper}.

If you have files that automatically render output (e.g. R Markdown), then you should check for the following:

  • 🎯 correct output
  • 🖼️ correct figures
  • ❓ new warnings
  • ‼️ new errors

Rendered Changes

🔍 Inspect the changes: https://github.com/UoMResearchIT/programming_with_python/compare/md-outputs..md-outputs-PR-56

The following changes were observed in the rendered markdown documents:

 05-defensive_programming.md | 108 ++++++++++++++++++--------------------------
 md5sum.txt                  |   2 +-
 2 files changed, 46 insertions(+), 64 deletions(-)
What does this mean?

If you have source files that require output and figures to be generated (e.g. R Markdown), then it is important to make sure the generated figures and output are reproducible.

This output provides a way for you to inspect the output in a diff-friendly manner so that it's easy to see the changes that occur due to new software versions or randomisation.

⏱️ Updated at 2026-04-13 11:39:47 +0000

@Scottan Scottan requested a review from douglowe November 14, 2025 12:01
github-actions bot pushed a commit that referenced this pull request Nov 14, 2025
Copy link
Copy Markdown
Collaborator

@andrewgait andrewgait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the sign test is likely better in this instance (and if they've done the introductory python course, there's something similar in that), so I would change it to use that test instead.

github-actions bot pushed a commit that referenced this pull request Apr 13, 2026
github-actions bot pushed a commit that referenced this pull request Apr 13, 2026
github-actions bot pushed a commit that referenced this pull request Apr 13, 2026
Copy link
Copy Markdown
Collaborator

@andrewgait andrewgait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me now - approved to merge.

@Scottan Scottan merged commit 312e3c3 into main Apr 13, 2026
5 checks passed
@Scottan Scottan deleted the 21-make-errors-example-into-a-function branch April 13, 2026 12:47
github-actions bot pushed a commit that referenced this pull request Apr 13, 2026
Auto-generated via `{sandpaper}`
Source  : 312e3c3
Branch  : main
Author  : scottan <33283688+Scottan@users.noreply.github.com>
Time    : 2026-04-13 12:47:22 +0000
Message : Merge pull request #56 from UoMResearchIT/21-make-errors-example-into-a-function

21 make errors example into a function
github-actions bot pushed a commit that referenced this pull request Apr 13, 2026
Auto-generated via `{sandpaper}`
Source  : c8f007d
Branch  : md-outputs
Author  : GitHub Actions <actions@github.com>
Time    : 2026-04-13 12:48:25 +0000
Message : markdown source builds

Auto-generated via `{sandpaper}`
Source  : 312e3c3
Branch  : main
Author  : scottan <33283688+Scottan@users.noreply.github.com>
Time    : 2026-04-13 12:47:22 +0000
Message : Merge pull request #56 from UoMResearchIT/21-make-errors-example-into-a-function

21 make errors example into a function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make errors example into a function

2 participants