7. String
7.1. Before Kattis
We’re going to do a bunch of linear searchers to start.
1
Write a function char_is_in_while(character, phrase)
that returns True
if the letter character
appears in the string phrase
, otherwise return False
. This function must use a while loop.
2
Write a function char_is_in_for(character, phrase)
that returns True
if the letter character
appears in the string phrase
, otherwise return False
. This function must use a for loop.
3
Write a function where_is_while(character, phrase)
that returns the index of the first occurrence of character
in phrase
, or return -1 if it does not exist. This function must use a while loop.
4
Write a function where_is_for(character, phrase)
that returns the index of the first occurrence of character
in phrase
, or return -1 if it does not exist. This function must use a for loop.
7.2. Kattis Problems
Grab a scrap piece of paper to start scratching your ideas down on paper. The problems are getting tricky enough where this really is becoming a requirement.
Warning
If you get really stuck on any question, move on to the next one! Do not get bogged down.
https://open.kattis.com/problems/autori (slow down and think about how you do this in real life).
https://open.kattis.com/problems/filip (is there an easy way to reverse a string in Python?)
If you finish this lab, go check out LeetCode. Sort the problems by Acceptance (click the table header) and start seeing if you can solve some of these problems.