OIM3600 - Computer Science for Business Students

Session 11 (10/02)

contain

Today's Agenda

  • Welcome/News/Announcements
  • Class Review
  • Lecture: Python Programming (cont.)
    • List, Dictionaries, Tuples, Sets
    • I/O

Welcome/News/Announcements

  • Homework feedback is provided in your GitHub issues or via PR.
    • Please respond.
  • Make sure you understand the code you use in your exercises and homework.
    • i.e. I may ask you to come to my office and explain any code that looks "interesting".
  • Communications:
    • Slack - for debugging, clarifications, real-time discussion, casual chat, etc.
    • Email - specify course # in subject title, e.g., "OIM3600: GitHub settings"
    • Meet with me in person during office hours at least once this semester.
  • Questions?

What we have learned so far

  • Code represent: 🔠🔢🈶😂🟥🟩🟦🖼 📽 🎼
  • Scratch
  • Git/GitHub
  • Programming
    • Functions: arguments, side effects, return values
    • Conditionals
    • Boolean expressions
    • Loops
    • Variables
    • Types: int, float, string, boolean, Nonetype, list, ...

Python Recommendations

Quick Quiz - Strings

  1. Are strings mutable?
  2. s = "Hello, World!"
    print(s[7:12]) # What is the output?
    
  3. How do you get a reversed version of a string s?
  4. How do you convert s to all lowercase letters?
  5. How do you split s into a list of words?
  6. How do you check if all characters in s are digits (0-9)?
  7. Write a function to check if a given string contains no vowels (i.e., none of letters 'a', 'e', 'i', 'o', 'u').
  8. Yesterday (20241001) is a perfect square number. Can you find the next one?

Quick Quiz - Lists

  1. Are lists mutable?
  2. nums = [1, 1, 2, 3, 5, 8, 13]
    print(nums[:-2])  # What is the output?
    
  3. How can you check if an element exists in nums?
  4. How do you reverse the order of elements in nums?
  5. How do you add an element to the end of nums?
  6. How do you remove the last element of nums?
  7. How can you find the mean of nums without using external libraries? What about the median?

Homework Feedback & Coding Style

  • GitHub Issues
    • Reply with feedback or questions if further discussion is needed.
    • Reply with evidence (e.g., code, screenshots) and close if resolved.
  • Functionality
    • Use pseudocode for complex or unclear code/algorithms.
    • Write additional test code when necessary.
  • Documentation
    • Add docstrings for every function that you create.
    • Write clear and relevant comments.
  • Styles
    • Use lowercase and underscore for folder and file names.
    • Choose clear and meaningful variable and function names.

Lectures

Conversions Between Data Structure Types

  1. string ⇔ list
  2. string ⇔ dictionary
  3. string ⇔ tuple
  4. string ⇔ set
  5. list ⇔ dictionary
  6. list ⇔ tuple
  7. list ⇔ set
  8. dictionary ⇔ tuple
  9. ...

--- # Quick Quiz - Dictionaries 1) Are dictionaries **mutable**? 2) Is it true that `dict` keys must be unique, but their values can be duplicated? 3) What is the output? ```py person = {'name': 'Guido', 'age': 68 } print('Guido' in person) ``` 4) How do you access the value associated with the key `'age'` in `person`? 5) How do you retrieve the value associated with a key, say `'country'`, in `person` safely, without raising an error if the key doesn't exist? 6) How do you add a new key-value pair `'city': 'Belmont, CA'` to `person`? 7) How can you create a dictionary `letter_count` that counts the frequency of each letter in a given string?