Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homework02 #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

wangrenfeng0
Copy link

Homework02 with both exercise 05 and 06.

@emma-data-works
Copy link
Owner

good job!

for last problem, i'd encourage you to think about the major difference between for and while, and how to fully take advantage of while loop.

while i <=len(numbers):
        if numbers[i] <=150:
            if numbers[i] % 5 ==0:
                divisible_by_5_while.append(numbers[i])
            i+=1
        else:
            break

can you think of a way to change to code above to use while without the break? do you need to iterate through all numbers in this list?

@wangrenfeng0
Copy link
Author

Yes.

def divisible_5_while(numbers):
    divisible_by_5_while = []
    i=0
    while numbers[i] <=150:
        if numbers[i] % 5 ==0:
            divisible_by_5_while.append(numbers[i])
        i+=1
    return 'The numbers which are divisible by 5 is {0}'.format(divisible_by_5_while)

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