OIM3640 - Problem Solving and Software Design

2025 Spring

Session 06 (2/06)

contain

Today's Agenda

Welcome/News/Announcements

  • Office Hours
    • By appointment: in-person (preferred) or Webex (please specify)
    • VSCode extension - Live Share
  • 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?

Generative AI Policy

  • AI tools like ChatGPT and Copilot can be helpful, but they are also a shortcut that prevents you from learning.
  • You may use them for generating ideas, explaining concepts, clarifying error messages, or reviewing code you've already written.
    • Be sure to acknowledge and cite any AI tools used, including the tool name and the output provided.
  • Using GenAI tools directly for exercises, homework assignments, quizzes, or similar tasks is considered an academic integrity violation.

What we have learned so far...

  • Variables, Expressions, Statements
  • Types: int, float, str, bool, None, other data structure types
  • Comments
  • Functions:
    • Syntax:
      def f(parameter):
          """ docstring """
          # function body
      
    • pass
    • Variables (defined inside a function) and parameters are local.
    • Discussions on print() vs. return: 1, 2, 3, 4...

Quick Quiz

  1. Can a function return multiple values?
  2. How do we check if variable a is an integer?
    • isinstance(a, int)
  3. What is the result?
    1. int(2.2)
    2. int('2.2')
    3. chr(ord('Z') - 1)
    4. round(1.5)
    5. round(2.5)
  4. What will be the output?
    def f():
        print('Hi')
    print(f())
    

About Exercise

  • Please check your OIM3640/Issues on GitHub.
    • Reply if we need to continue the conversation.
    • Comment (with evidence) and Close if you think it is fixed.
  • File/folder names: use lowercase and underscore, i.e., session04/type_demo.py
  • Use more Python comments and be ready to write pseudo-code and docstrings
  • If you have any question regarding

Docstring! Docstring! Docstring!

Revisit Exercises

  • Exercise 3-5:
    • Create your own version of my_abs() to replicate the built-in abs().
    • Use Psuedo-code.
    • How does module work?
  • Exercise 6:
    • quadratic()

Revisit Exercises

  • def quadratic(a, b, c):
        """ ... """
        a = float(input('Enter a: '))
        b = float(input('Enter b: '))
        c = float(input('Enter c: '))
        ...
    
  • return(-x) -> return -x
  • if some_condition == True: -> if some_condition:
  • Make sure that you include the code that tests (aka. calls) the function(s).

Python Best Practices

  • Always format your code before saving or running it.
  • Use f-strings for printing results.
  • Write docstrings for each function you create.
  • Use Python Tutor to visualize code execution.

Lecture