대학생 코딩 과제 대행 java, python, oracle 두 번째

https://open.kakao.com/o/s3aMpbA
이번에는 저번과제와는 다르게 python 과제가 들어왔다.

default로 설치된 파이선 폴더의 README.txt의 Copyright (c) 다음부분의 년도 숫자들의 합을

출력하는 파이썬 코드를 작성하세요.


아래는 README.txt 의 경로입니다.

C:\Python27\README.txt or C:\Python34\README.txt




위에 요구사항처럼 파이썬을 설치하면 README.txt 텍스트 파일이 있는데,
조건에 해당하는 줄을 읽어서 년도들을 다 더하는 코드를 짜면 되는거였다.

python3.5로 짰다.

# -*- coding: UTF-8 -*-
import re

strline =""
with open('C:\Python35\README.txt','r') as f:
    for line in f.readlines():
        if("Copyright (c)"in line):
            strline+=line[14:]
        if("2012" in line):
            strline+=line




print(strline)

stre = re.compile('[a-zA-Z]|,|\.')
alphaBet = stre.findall(strline)
for i in alphaBet:
    strline = strline.replace(i,'')


strline = strline.replace('-',' ')
print(strline)


strline = strline.split()

print(strline)

hap = 0;
for i in range(0,len(strline)):
    print(int(strline[i]))

    hap = hap + int(strline[i])

print(hap)



실행결과

댓글

이 블로그의 인기 게시물

About Kafka Basic

About JVM Warm up

About ZGC

Spring Boot Actuator readiness, liveness probes on k8s

About G1 GC

sneak peek jitpack

About idempotent

C 언어 구조체의 포인터 멤버 변수

Synology NAS에 MariaDB 10에 Mysql workbench로 원격접속하기

About Websocket minimize data size and data transfer cost on cloud