OIM3640 - Problem Solving and Software Design

2025 Spring

Session 05 (2/04)

contain

Today's Agenda

  • Welcome/News/Announcements
  • Class review
  • Exercise feedback
  • Lecture

Welcome/News/Announcements

  • Class GitHub:
  • Communications:
    • Meet with me in person during office hours at least once this semester.
    • Email - specify course # in subject title, e.g., "OIM3640: GitHub settings"
    • Use Slack/GitHub when asking code-related questions
  • Questions?

Happy Groundhog Day!

Keeping Up with Each Chapter

  • Read the chapter after every class, regardless of whether we finish it in class.
  • Create a separate .py file for that chapter and re-run all the demo code.
    • Experiment with variations or create derivations from the examples.
    • Ask "what if" questions.
    • Take notes as you experiment.
    • If you're stuck, ask ChatGPT or post your questions on Slack.
  • Pre-read the next chapter before class, making note of anything you think might be challenging or interesting.

What we have learned so far...

  • Variables
  • Expressions
  • Statements
  • Types:
    • int, float
    • str
    • bool
    • None
    • list, dict, tuple, set,...

Quick Quiz

  1. What will be printed? print(r'It\'s ok.')
  2. How can we generate a random floating-point number within the interval [0.0, 1.0)?
    • random.random()
  3. How can we generate a random floating-point number within [0.0, 10.0)?
    • random.random() * 10
  4. How can we generate a random integer in the range [0, 10) (excluding 10)?
    • math.floor(random.random() * 10)
    • random.randint(0, 9)
  5. What is the type and the value of the expression in line 2 below?
    year = 2020
    year % 4 == 0 and year % 100 != 0 or year % 400 == 0
    

Exercise Feedback

  • Please check your OIM3640/Issues on GitHub.
    • Reply if further discussion is needed.
    • Reply with evidence and close the issue if you believe it is resolved.
  • File/folder names - use lowercase and underscore, i.e., session04/ex_03.py
  • Use more Python comments and be ready to write pseudo-code and docstrings
  • If you have any question regarding

Issues/Errors from Exercises

  • days = current_time / 86400
    • Do not use magic numbers!
      • Avoid using hardcoded values without explanation in your code, as these can be difficult to understand or maintain.
    • When declaring CONSTANT_VARs, use all uppercase letters and separate words with underscores.
      • i.e. SECONDS_IN_A_DAY = 86400
  • Don't name file time.py or name variable time.
    • Because it can cause conflicts with the built-in Python module time.
  • Use f-string for print.

Lecture