PY4E Assignment 13

2021. 2. 26. 17:20언어영역/Python

정말 드럽게 힘든 여정이었다. 이 코드에만 쓴 시간이 거진 네시간은 되는 듯하다...  여러 가지 문제들을 마주했고 이젠 코드에 대해서만 설명한다. 

#BASIC
import urllib.request, urllib.parse, urllib.error
import xml.etree.ElementTree as ET
fuckthecode = list()


#you can just use input("") etc.
url = "http://py4e-data.dr-chuck.net/comments_1173717.xml"
uh = urllib.request.urlopen(url)

#cause' the uh file is from internet decode it when we read it.
data = uh.read().decode()

tree = ET.fromstring(data)
lst = tree.findall('.//count')

#Now we got list of the exact text file we wanted, we don't need things like .find() anymore.
#Instead, we read the lines of the list and print the items of them which are strings.

for items in lst:
    fuckthecode.append(items.text)
# I need to int() so that I can add them set variable k as 0
k = int(0)
for num in fuckthecode:
    k = k + int(num)
#or you can just use sum().
print(k)

고생했다... 나!