Python Ex 8.5: in python4e

Hay , hope you are doing well,

it’s right answer for that quiz, but I feel that the quiz asked for a specific answer need help , and the line :
if len(words) == 0 : continue can u tell me another way to do the same ?

link of quiz :
https://www.py4e.com/tools/pythonauto/?PHPSESSID=f42fa792ce788dcae11b092ae158c67e

Hi @Mahmmmoud I cannot access to your link since is expired session. :cry:

Well, the most similar to continue is pass
However there are differences, continue transfers the control of the loop to the beginning. While pass is a definitive pass (ignore the failed loop)
There is another commonly misunderstood, break is the contrary to pass if the condition in the loop is true, then it will break the flow of execution.
For more info:

Hope this helps

1 Like

@AndyG Thx for your response :blush: , I’m really newbie in python right now so , thx i wasn’t know if pass exist till u tell me , but i asked about a way to simplify the code more than this , and i hope that link is not expired PY4E - Python for Everybody ,
to access the Autograder : Exercise 8.5 you need to login :wink:

Hi @Mahmmmoud ,

You could streamline your code by first finding a line that starts with 'From ’ and then splitting and printing words[1].

fhand = open(fname)
count = 0
for line in fhand:
    if line.startswith('From '):
        words = line.split()
        print statement
        increment count
print count

Hope this helps!

2 Likes

@manjupillai16 Wow Amazing solution :star_struck:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.