OIM3640 - Problem Solving and Software Design

2025 Spring

Session 14 (3/11)

contain

Today's Agenda

  • Welcome/News/Announcements
  • Review
  • Quiz 3
  • Debugging Practice
  • Lectures:

Welcome/News/Announcements

  • Assignment 1: Feedback will be given on GitHub/Issues
  • Next Class:
    • API and parsing JSON data
    • Please register on OpenWeather and get an API Key (free tier for Current weather and forecasts collection, not One Call API 3.0) before next class.
    • Do not share your API key with others or post it on 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?

What we have learned so far...

  • Variables, Expressions, Statements
  • Types: int, float, boolean, Nonetype, string, list
  • Functions
  • Conditional Statements
  • Iterations: for, while
  • Pseudo-code
  • Debugging

Quick Quiz

  • How do you check if a string is all uppercase?
    • How to check if it contains at least one uppercase letter?
  • Are lists mutable?
  • What are some common functions that work on both strings and lists?
  • If you want to add one item to end of a list, which method should you use - append() or extend()?
  • If you want to sort a list in-place, which should you use - sort() or sorted()?
  • How do you make a copy of a list?

Exercises

Quiz 3

  • 📃 Paper Section (90%)
    • Close your computer. Write code on the given paper.
    • Once finished, put your pen away or into your bag.
  • 💻 VSCode Section (10%)
    • Open your computer and create quiz3.py inside quiz folder.
    • Download common_passwords.txt (https://bit.ly/python-quiz-3) to data folder
    • Transcribe your code from the paper to quiz3.py. You may fix any errors.
    • You are NOT allowed to seek help from other people or AI tools.
    • When finished, commit and push to GitHub.
  • 📌 Next Slide: Quiz Grading Rubric
  • 💡 If you enjoyed this problem, try this Kata on CodeWars - Catching Car Mileage Numbers.

Quiz Grading Rubric

Score Description
100 The code is fully correct, runs without errors, and meets all requirements.
80~90 The code is mostly correct and functional, but may have minor issues (e.g., small logical mistakes, common typos). Fixes are straightforward.
50~60 The code has significant issues and may not be run properly, but includes clear effort, pseudo-code, or comments that show understanding.
20~30 The submission is incomplete, poorly structured, or lacks sufficient effort to demonstrate a serious attempt.
0 No submission or completely off-topic answer.

Recommendations

Learn Python the Hard Way

  • A Note on Practice and Persistence

    If you give up, you won't ever reach this point. You will hit the first confusing thing (which is everything at first) and then stop. If you keep trying, keep typing it in, keep trying to understand it and reading about it, you will eventually get it. If you go through this whole book, and you still do not understand how to code, at least you gave it a shot. You can say you tried your best and a little more, and it didn't work out, but at least you tried. You can be proud of that.

Debugging Practice

  • 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.
  • Use above methods to find out why is_reverse is not working correctly.

Python Tips - Rubber Duck Debugging

alt=""

Lecture

--- # Assignment 1 Feedback 1) The starting point is not always `(0,0)`, if you read Q1's `main()` carefully. 2) Please use **comments** when necessary. * E.g., `if dir == 1: # What does 1 mean?` 3) `turtle.lt(90)` might not be the correct direction as expected. * You could use `setheading()` or `goto(x, y)`. 4) Only one `if __name__ == '__main__':` should be in a `.py` file. 5) Avoid using variable names such as `sum`, `round`, `class`. 6) Other Suggestions: 1) Break big function to smaller ones. 2) Use better data structures, once we learn `dict`, etc. 3) Extension ideas. --- ![bg 80% drop-shadow](images/hw1-feedback-chatgpt.png) --- ![bg 80% drop-shadow](images/hw1-feedback-chatgpt-2.png) --- # Assignment Feedback & Code Review - Submitting your homework is not the final step. - Please review my feedback on GitHub (via issues of your hw1 repo) - Make any necessary modifications to improve your work. - Respond to my feedback by commenting on the issues. - I also recommend using **ChatGPT/Claude** for code review. - What would be a good prompt? * Example: ***"I am a student learning Python and working on an assignment. Can you review my code and suggest improvements? Please identify any errors, inefficiencies, or areas where I can optimize my solution while keeping in mind that I am still learning the fundamentals."***

- Download following files from **OIM3640/resources/code** to ***session14*** folder - *json_example.py* - *json_example2.py* - *people_in_space.py*