Closed dpwl1000 closed 4 years ago
I inserted the below in my atom app and saved the file name as week2.py
import re
file = open('Sample_data.txt', 'r')
sum = 0
for line in file:
numbers = re.findall('[0-9]+', line)
for number in numbers:
sum = sum + int(number)
print (sum)
And then I put the below in my command prompt
-ommited the part of command-
C:\Users\cindy\OneDrive\바탕 화면\py4e>week2.py
Traceback (most recent call last):
File "C:\Users\cindy\OneDrive\바탕 화면\py4e\week2.py", line 3, in
FileNotFoundError: [Errno 2] No such file or directory: 'Sample_data.txt'
C:\Users\cindy\OneDrive\바탕 화면\py4e>
But I got the above error and I don't get what I did wrong in the process...
I did save the txt file as Sample-data.txt in the same file as week2.py file.
What do I have to change..?
I have tried changing the file name as regex_sum_42.txt instead of Sample_data.txt but it still doesnt work...
I inserted the below in my atom app and saved the file name as week2.py
import re
file = open('Sample_data.txt', 'r')
sum = 0
for line in file:
numbers = re.findall('[0-9]+', line)
for number in numbers:
sum = sum + int(number)
print (sum)
And then I put the below in my command prompt
-ommited the part of command-
C:\Users\cindy\OneDrive\바탕 화면\py4e>week2.py
Traceback (most recent call last):
File "C:\Users\cindy\OneDrive\바탕 화면\py4e\week2.py", line 3, in
file = open('Sample_data.txt', 'r')
FileNotFoundError: [Errno 2] No such file or directory: 'Sample_data.txt'
C:\Users\cindy\OneDrive\바탕 화면\py4e>
But I got the above error and I don't get what I did wrong in the process...
I did save the txt file as Sample-data.txt in the same file as week2.py file.
What do I have to change..?
I have tried changing the file name as regex_sum_42.txt instead of Sample_data.txt but it still doesnt work...