{{ message }}

# Add solution to exercises, lesson 5 #607

Open
wants to merge 1 commit into
Choose a base branch

### Are you sure you want to change the base?

Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
from
Open

# Add solution to exercises, lesson 5#607

wants to merge 1 commit into from

## Conversation

### Lisanna commented Jan 14, 2019

 Add solution to "What Is Truth?" and "That’s Not Not What I Meant"
``` Update 05-cond.md ```
``` f858897 ```
`Add solution to "What Is Truth?" and "That’s Not Not What I Meant"`
approved these changes

### annefou left a comment

 Thanks for adding solutions to the exercises. It looks good on my side.
approved these changes

### annefou left a comment

 Excellent! Thanks.
changed the title Add solution to exercises, lesson 2 Add solution to exercises, lesson 5 Jan 14, 2019
requested changes

### maxim-belkin left a comment • edited

 Thanks, @Lisanna, for contributing to the lesson! Please see my comments above below.
 > > ## Solution > > A non-empty string, non-empty list and 1 are considered true. > > An empty string, an empty list and 0 are considered false. > {: .solution}

#### maxim-belkin Jan 14, 2019 Contributor

I'm dubious here: proposed solution is not a rule but rather a summary of facts presented in the exercise. I'd suggest to say something like: `A string is "true" as long as it contains at least one symbol` and `A list is "true" as long as it contains at least one element`. It does not have to be that exact wording, but something along these lines.

 > > ## Solution > > Again, empty string is not true, and non-empty string is true. > > Not (not true, i.e. false) is true. > {: .solution}

#### maxim-belkin Jan 14, 2019 Contributor

Um, I'm confused. The exercise says:

After reading and running the code below,
write some `if` statements that use `not` to test the rule
that you formulated in the previous challenge.

#### annefou Jan 15, 2019 Contributor

Should we add a solution such as:

if not not '':
print('empty string is true')
if not not 'word':
print('word is true')
if not not []:
print('empty list is true')
if not not [1, 2, 3]:
print('non-empty list is true')
if not not 0:
print('zero is true')
if not not 1:
print('one is true')

#### maxim-belkin Jan 15, 2019 Contributor

write some `if` statements that use `not` to test the rule
that you formulated in the previous challenge.

So, we have to formulate the rule first.
If the rule is

A string is "true" as long as it contains at least one symbol.
A list is "true" as long as it contains at least one element.
Any non-zero number is "true".

Then we could write:

if not 0:
print('not 0 is true')
if not '0':
print('this will not print because our string is not empty')
if not []:
print('not empty list is true')
if not [[]]:
print('this will not print because our list has one element - another empty list')

#### annefou Jan 15, 2019 Contributor

Yes I agree. And it would be much clearer!