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

Typo on Chapter 11 #218

Closed
ck39 opened this issue Aug 11, 2019 · 2 comments
Closed

Typo on Chapter 11 #218

ck39 opened this issue Aug 11, 2019 · 2 comments

Comments

@ck39
Copy link

ck39 commented Aug 11, 2019

Exercise 2 at the bottom of chapter 11 Regex (https://www.py4e.com/html3/11-regex)
The solution to the average for 'mbox-txt':

Enter file:mbox.txt
38444.0323119

I think the answer should be 38549.7949721 ?

csev added a commit that referenced this issue Aug 14, 2019
@csev
Copy link
Owner

csev commented Aug 14, 2019

Thanks - I reworded to ask for an integer and fixed the numbers. It takes 30 minutes for the online versions to update.

@csev csev closed this as completed Aug 14, 2019
@Shubham6059
Copy link

I suppose the answer will be 38444 instead of 38549.

import re

fh = open("mbox.txt")
count = 0
total = 0
for line in fh:
    line = line.rstrip()
    lst = re.findall('[A-Za-z]+ [A-Za-z]+: ([0-9]+)', line)
    if len(lst) > 0:
        for x in lst:
            total += int(x)
            count += 1

print(total // count)

I used this code to fetch the result.
For mbox-short.txt the result is correct as mentioned i.e. 39756
while for mbox.txt its 38444 instead of 38549.

I would be happy if you could correct me if I'm wrong. :)
@csev @ck39

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

No branches or pull requests

3 participants