You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#In this assignment you will read through and parse a file with text and numbers. You will extract all the numbers in the file and compute the sum of the numbers.
4
+
#Data Files
5
+
6
+
#We provide two files for this assignment. One is a sample file where we give you the sum for your testing and the other is the actual data you need to process for the assignment.
7
+
8
+
#Sample data: http://py4e-data.dr-chuck.net/regex_sum_42.txt (There are 90 values with a sum=445833)
9
+
#Actual data: http://py4e-data.dr-chuck.net/regex_sum_2003014.txt (There are 97 values and the sum ends with 724)
10
+
11
+
#These links open in a new window. Make sure to save the file into the same folder as you will be writing your Python program. Note: Each student will have a distinct data file for the assignment - so only use your own data file for analysis.
12
+
13
+
#Data Format
14
+
15
+
#The file contains much of the text from the introduction of the textbook except that random numbers are inserted throughout the text. Here is a sample of the output you might see:
16
+
17
+
#Why should you learn to write programs? 7746
18
+
#12 1929 8827
19
+
#Writing programs (or programming) is a very creative
20
+
#7 and rewarding activity. You can write programs for
21
+
#many reasons, ranging from making your living to solving
22
+
#8837 a difficult data analysis problem to having fun to helping 128
23
+
#someone else solve a problem. This book assumes that
24
+
#everyone needs to know how to program ...
25
+
26
+
#The sum for the sample text above is 27486. The numbers can appear anywhere in the line. There can be any number of numbers in each line (including none).
27
+
28
+
#Handling The Data
29
+
30
+
#The basic outline of this problem is to read the file, look for integers using the re.findall(), looking for a regular expression of '[0-9]+' and then converting the extracted strings to integers and summing up the integers.
0 commit comments