0% found this document useful (0 votes)
3 views6 pages

Programming 5 DF

The document discusses various functions and their issues related to if...else conditionals and For loops in programming. It highlights specific errors in the code, such as incorrect indentation and the use of variables, and provides solutions to correct them. Additionally, it mentions the behavior of functions regarding string evaluations and the impact of the 'not' keyword on output values.

Uploaded by

shumbapraise71
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Programming 5 DF

The document discusses various functions and their issues related to if...else conditionals and For loops in programming. It highlights specific errors in the code, such as incorrect indentation and the use of variables, and provides solutions to correct them. Additionally, it mentions the behavior of functions regarding string evaluations and the impact of the 'not' keyword on output values.

Uploaded by

shumbapraise71
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.In the if...else conditional, it ends the execution of the program immediately it comes across a True value.

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

programmed to return a False value (not because it didn't find uppercase

letters).
Screenshot.
Reference.

Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press. This book is licensed

under Creative Commons Attribution-NonCommercial 3.0 Unported

You might also like