OIM3640 - Problem Solving and Software Design

2025 Spring

Session 11 (2/27)

contain

Today's Agenda

Welcome/News/Announcements

  • Assignment 1: Due Friday, 2/28
  • Make sure you understand the code you use in your exercises and homework.
    • I may ask you to come to my office and explain any code that looks "interesting".
  • 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?

What we have learned so far...

  • Variables, Expressions, Statements
  • Types: int, float, string, boolean, Nonetype, other data structures
  • Functions
  • Conditional Statements
    • if...elif...else
    • recursion
  • Pseudo-code
  • Iterations
    • for
    • while

Quick Quiz

  1. Give any two string methods.
    • strip(), split(), replace(), isupper() vs upper()...
  2. Are strings mutable?
  3. a = 'babson'
    b = 'like'
    print('kebab' in 2 * (a + b))  # What is the output?
    
  4. How do we get the reversed version of a string, s?
  5. How do we find the middle character(s) of a string, s?
  6. How do we check if a string contains no vowels ('a', 'e', 'i', 'o', 'u')?
  7. This year (2025) is a perfect square number. Can you find the next one?

Q & A

  • Questions from exercises, quizzes, assignments.
  • Issues on GitHub
  • Any question today?

Quick Quiz - 1. True or False?

def any_uppercase1(s):
    for c in s:
        if c.isupper():
            return True
        else:
            return False
  1. print(any_uppercase1('iPhone'))
  2. print(any_uppercase1('Babson'))
  3. print(any_uppercase1('NBA'))

Quick Quiz - 2. True or False?

def any_uppercase2(s):
    for c in s:
        if 'c'.isupper():
            return True
        else:
            return False
  1. print(any_uppercase2('iPhone'))
  2. print(any_uppercase2('Babson'))
  3. print(any_uppercase2('NBA'))

Quick Quiz - 3. True or False?

def any_uppercase3(s):
    for c in s:
        flag = c.isupper()
    return flag
  1. print(any_uppercase3('iPhone'))
  2. print(any_uppercase3('Babson'))
  3. print(any_uppercase3('NBA'))

Quick Quiz - 4. True or False?

def any_uppercase4(s):
    flag = False
    for c in s:
        flag = flag or c.isupper()
    return flag
  1. print(any_uppercase4('iPhone'))
  2. print(any_uppercase4('Babson'))
  3. print(any_uppercase4('NBA'))

Quick Quiz - 5. True or False?

def any_uppercase5(s):
    for c in s:
        if not c.isupper():
            return False
    return True
  1. print(any_uppercase5('iPhone'))
  2. print(any_uppercase5('Babson'))
  3. print(any_uppercase5('NBA'))

Quick Quiz - 6. True or False?

def any_uppercase6(s):
    for c in s:
        if c.isupper():
            break
            return True
    return False
  1. print(any_uppercase6('iPhone'))
  2. print(any_uppercase6('Babson'))
  3. print(any_uppercase6('NBA'))

More Practice

  1. ⭐ Codingbat (OIM3640/codingbat)
  2. Python Challange
  3. More learning resources

How to Debug

  • Format your code first: Alt (⌥ option if macOS) + Shift + F in VS Code.
  • print()
  • PythonTutor.com
  • Debugging in VS Code
    1. Set breakpoints to pause execution at specific lines.
    2. Run debugger: Press F5 to Start Debugging
      1. "Continue" ( F5 ): Keep running until next breakpoint or stopping point.
      2. "Step Over" ( F10 ): Go through code line by line, skip over functions.
      3. "Step Into" ( F11 ): Step into functions and trace each line inside them.
    3. Inspect Variables: Use "VARIABLES" panel or "WATCH" panel.

Lecture