Skip to content

Control Flow practice#2

Open
laraib-W wants to merge 2 commits into
masterfrom
control_flow
Open

Control Flow practice#2
laraib-W wants to merge 2 commits into
masterfrom
control_flow

Conversation

@laraib-W

@laraib-W laraib-W commented Aug 4, 2022

Copy link
Copy Markdown
Owner

Practiced control flow python

Comment thread src/control_flow/test_continue.py Outdated
@@ -18,12 +18,12 @@ def test_continue_statement():

for number in range(0, 10):
# Check if remainder after division is zero (which would mean that number is even).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment got staled now, as you've changed the logic.

# Iterating over a sequence does not implicitly make a copy. The slice notation makes this
# especially convenient:
for word in words[:]: # Loop over a slice copy of the entire list.
for word in words.copy(): # Loop over a slice copy of the entire list.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for changing this?

Comment thread src/control_flow/test_for.py Outdated
# To iterate over the indices of a sequence, you can combine range() and len() as follows:
words = ['Mary', 'had', 'a', 'little', 'lamb']
concatenated_string = ''
concatenated_string2 = ' '.join(words)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an example for testing for control, so let's add an example for that.

Comment thread src/control_flow/test_for.py Outdated
concatenated_string += str(word_index) + ' ' + word + ' '

assert concatenated_string == 'Mary had a little lamb '
assert concatenated_string == '0 Mary 1 had 2 a 3 little 4 lamb '

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a good example for testing the for control.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants