-
-
Save MichelleDalalJian/4d630b054e647b2d61a5ed9bcc385f10 to your computer and use it in GitHub Desktop.
| import re | |
| hand = open("regex_sum_24962.txt") | |
| x=list() | |
| for line in hand: | |
| y = re.findall('[0-9]+',line) | |
| x = x+y | |
| sum=0 | |
| for z in x: | |
| sum = sum + int(z) | |
| print(sum) |
Hello,
As there are many answers to this assignment, mine is the one from a noob that coudln't write a code 1 month ago so it's not that sofisticated but it works !
import re
hand = open("Your_file_name")
lst = list()
for line in hand:
stuff = re.findall("[0-9]+",line)
for num in stuff:
lst.append(int(num))
print("Sum = ",sum(lst))
Actual data: http://py4e-data.dr-chuck.net/regex_sum_2371597.txt (There are 82 values and the sum ends with 487
sum end with 487
i need help with this.
Actual data: http://py4e-data.dr-chuck.net/regex_sum_2371597.txt (There are 82 values and the sum ends with 487 sum end with 487 i need help with this.
You can copy paste my program and replace "Your_file_name" by your URL, it should work.
Ps: don't forget to indent correctly ;)
Actual data: http://py4e-data.dr-chuck.net/regex_sum_2301852.txt (There are 87 values and the sum ends with 524) I need help with this