CSCI 161

Course Notes

  • 1. Introduction and Output
  • 2. Print, Values, Variables, Types
  • 3. Statements and Expressions
  • 4. Input and Changing Types
  • 5. Functions
  • 6. Propositional Logic
  • 7. Testing Your Code and Type Hints
  • 8. If/Else
  • 9. Putting Things Together
  • 10. Loops
  • 11. Strings & Objects
  • 12. Lists
  • 13. References
  • 14. Aliases & List Trivia
  • 15. Tuples, Dictionaries, and Sets
  • 16. Debugging
  • 17. File IO
  • 18. Exceptions
  • 19. Objects I — Introduction
  • 20. Objects II — More on Methods
  • 21. Objects III — Interacting Objects
  • 22. Unittest
  • 23. Objects IV — Data Structures
  • 24. Searching and Complexity
  • 25. Sorting Algorithms

Labs

  • 1. Hello World
  • 2. Functions
  • 3. Testing
  • 4. Conditionals
  • 5. Car Rental
  • 6. Loops & Linear Search
    • 6.1. Pre Lab Exercises
    • 6.2. Before Kattis
    • 6.3. Kattis Problems
  • 7. Lists
  • 8. 2D Lists
  • 9. References & More Lists
  • 10. Objects
  • 11. Unit Testing Objects
  • 12. Data Structures

Assignments

  • 1. Density of Starbucks
  • 2. Zombie Infections
  • 3. Tic-Tac-Toe
  • 4. Country Catalogue

Getting Started

  • Getting set up for CSCI 161

Outline

  • Computer Science 161 Section 66 — Introduction to Programming
  • Course Schedule
CSCI 161
  • 6. Loops & Linear Search
  • View page source

6. Loops & Linear Search

  • Feel free to use your laptop

  • You are strongly encourage to work with others

    • When you get stuck, ask those sitting around you for help

    • Get used to working together in the labs

    • Peer teaching and peer learning has been empirically shown to be very effective

6.1. Pre Lab Exercises

  1. Chapter 7 exercise(s)

    • 9 What is a “triangle number”? (no assert test for this)

    • 14 (use assert to test instead of their test function)

    • 15 (use assert to test instead of their test function) — not required, but recommended

  2. Chapter 8 exercise(s)

    • 3

    • 9 (use assert to test instead of their test function) — not required, but recommended

    • 10 (use assert to test instead of their test function) — not required, but recommended

    • 11 (use assert to test instead of their test function) — not required, but recommended

    • 12 (use assert to test instead of their test function) — not required, but recommended

    • 13 (use assert to test instead of their test function) — not required, but recommended

  3. Write assertion tests for each of your functions above, except for Chapter 7 exercise 9, as it requires print

6.2. Before Kattis

  1. Write a function count_to_n_while(n: int): to print out each number from \(0\) – \((n - 1)\)

    • This function must use a while loop

    • This function will not return anything

  2. Write a function count_to_n_for(n: int): to print out each number from \(0\) – \((n - 1)\)

    • This function must use a for loop

    • This function will not return anything

  3. Write a function character_is_in_while(needle: str, haystack:str) -> bool:

    • The function will return True if needle exists within haystack and False otherwise

    • This function must use a while loop

  4. Write a function character_is_in_for(needle: str, haystack:str) -> bool:

    • The function will return True if needle exists within haystack and False otherwise

    • This function must use a for loop

  5. Write a function character_is_at_while(needle: str, haystack:str) -> int:

    • The function will return the index of the first occurrence of needle within haystack and -1 if it is not found

    • This function must use a while loop

  6. Write a function character_is_at_for(needle: str, haystack:str) -> int:

    • The function will return the index of the first occurrence of needle within haystack and -1 if it is not found

    • This function must use a for loop

6.3. Kattis Problems

  • You should be using a scrap piece of paper to work out the ideas for the following problems

    • The problems you are to solve are getting too complex to try to solve by just coding

    • Trying to solve problems by just typing away will not yield success

  1. https://open.kattis.com/problems/timeloop

  2. https://open.kattis.com/problems/oddities

  3. https://open.kattis.com/problems/fizzbuzz

  4. https://open.kattis.com/problems/sibice

  5. https://open.kattis.com/problems/bus

  6. https://open.kattis.com/problems/datum

  7. https://open.kattis.com/problems/dicecup

  8. https://open.kattis.com/problems/autori

  9. https://open.kattis.com/problems/apaxiaaans

  10. https://open.kattis.com/problems/hissingmicrophone

  11. https://open.kattis.com/problems/trik

  12. https://open.kattis.com/problems/pot

  13. https://open.kattis.com/problems/filip

  14. https://open.kattis.com/problems/reversebinary

  15. https://open.kattis.com/problems/sevenwonders

  16. https://open.kattis.com/problems/zamka

Previous Next

© Copyright 2022, James Hughes, Taras Mychaskiw, & Jean-Alexis Delamer.

Built with Sphinx using a theme provided by Read the Docs.