대상: python을 해본 적이 없는 분
실습은 이곳에서 진행합니다.
“REPL : Read-Eval-Print Loop의 약자로 스칼라, 파이썬 등 대화형 환경
콘솔에서 컴파일 없이 코드를 입력하고 출력 결과를 확인 할 수 있는 환경”
Python3을 선택합니다.vWhg5j
실행화면 4XLb32
10 미만의 자연수에서 3과 5의 배수를 구하면 3, 5, 6, 9이다. 이들의 총합은 23이다.
1000 미만의 자연수에서 3의 배수와 5의 배수의 총합을 구하라.
result = 0
for n in range(1, 1000):
if n % 3 == 0:
result += n
if n % 5 == 0:
result += n
print(result)
result = 0
for n in range(1, 1000):
if n % 3 == 0:
result += n
if n % 5 == 0:
result += n
print(result)
result = 0
for n in range(1, 1000):
if n % 3 == 0:
result += n
if n % 5 == 0:
result += n
print(result)
result = 0
if n % 3 == 0:
if n % 5 == 0:
result += n
for n in range(1, 1000):
if n % 3 == 0:
result += n
주민등록번호를 포함하고 있는 텍스트가 있다.
이 텍스트에 포함된 모든
주민등록번호의 뒷자리를 * 문자로 변경하시오.
data = """
park 800905-1049118
kim 700905-1059119
"""
result = []
for line in data.split("\n"):
word_result = []
for word in line.split(" "):
if len(word) == 14 and word[:6].isdigit() and word[7:].isdigit():
word = word[:6] + "-" + "*******"
word_result.append(word)
result.append(" ".join(word_result))
print("\n".join(result))
주민등록번호를 포함하고 있는 텍스트가 있다.
이 텍스트에 포함된 모든
주민등록번호의 뒷자리를 * 문자로 변경하시오.
import re
data = """
park 800905-1049118
kim 700905-1059119
"""
pat = re.compile("(\d{6})[-]\d{7}")
print(pat.sub("\g<1>-*******", data))