Programming 5 DF
Programming 5 DF
So in a
string of 4 characters, a For loop will repeat a process 4 times, taking a character from the string each time. When
the if...else conditional gets a True value in either of the return values and ends the program.
In the code above, all 3 arguments in the function call have lowercase strings, so the output should have been all
True, but the output was False, True, and False. To correct this, the else branch should be
indented outside the if condition, the same level as the For Loop.
Screenshot.
2. This second function checks that only the string "e" lower, which always returns True. So the argument in the
function call only enables it to run and ends the program. To correct this error, first, use the variable in the For Loop
statement in place of "c" and then lace the else branch of the if...else conditional outside the if condition.
Screenshot.
3. In this third function, the result only depends on the last letter of the given string, as shown in the output
Screenshot.
4. This fourth function finally returned an expected value.
Screenshot.
5.The last function, instead of looking out for lowercase letters, the function will be looking for uppercase letters
because of the 'not' keyword, which has reversed it. And it will return a False value because it has been
letters).
Screenshot.
Reference.
Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press. This book is licensed