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
-
9 What is a “triangle number”? (no
asserttest for this)14 (use
assertto test instead of theirtestfunction)15 (use
assertto test instead of theirtestfunction) — not required, but recommended
-
3 (use
assertto test instead of theirtestfunction) — not required, but recommended7 (use
assertto test instead of theirtestfunction) — not required, but recommended8 (use
assertto test instead of theirtestfunction) — not required, but recommended9 (use
assertto test instead of theirtestfunction) — not required, but recommended10 (use
assertto test instead of theirtestfunction) — not required, but recommended11 (use
assertto test instead of theirtestfunction) — not required, but recommended12 (use
assertto test instead of theirtestfunction) — not required, but recommended13 (use
assertto test instead of theirtestfunction) — not required, but recommended
Write assertion tests for each of your functions above, except for Chapter 7 exercise 9, as it requires
print
6.2. Before Kattis
Write a function
count_to_n_while(n: int):to print out each number from \(0\) – \((n - 1)\)This function must use a
whileloopThis function will not return anything
Write a function
count_to_n_for(n: int):to print out each number from \(0\) – \((n - 1)\)This function must use a
forloopThis function will not return anything
Write a function
character_is_in_while(needle: str, haystack:str) -> bool:The function will
returnTrueifneedleexists withinhaystackandFalseotherwiseThis function must use a
whileloop
Write a function
character_is_in_for(needle: str, haystack:str) -> bool:The function will
returnTrueifneedleexists withinhaystackandFalseotherwiseThis function must use a
forloop
Write a function
character_is_at_while(needle: str, haystack:str) -> int:The function will
returnthe index of the first occurrence ofneedlewithinhaystackand-1if it is not foundThis function must use a
whileloop
Write a function
character_is_at_for(needle: str, haystack:str) -> int:The function will
returnthe index of the first occurrence ofneedlewithinhaystackand-1if it is not foundThis function must use a
forloop
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