def para_func(*para):
    result = 0
    for num in para:
        result = result + num
    return result


변수선언

>>> hap = 0

실행

>>> hap = para_func(10,20,30)

>>> print(hap)

60




def para_func(*para):
    result = 0
    for num in para:
        result = result + num
    return result

#변수선언
hap = 0
v1,v2,v3 = 0,0,0

#메인코드
while True :
    v1 = int(input("v1 = "))
    v2 = int(input("v2 = "))
    v3 = int(input("v3 = "))
    hap = para_func(v1,v2,v3)
    print("hap=%d"%hap)
    if hap == 0 :
            print("프로그램 종료")
            break


v1 = 10

v2 = 20

v3 = 30

hap=60


#모듈 -> 함수의 집합으로 다른 프로그램에서도 활용하고자 할 때 사용
def func1() :
    print("func1()함수 실행")

def func2() :
    print("func2()함수 실행")

def func3() :
    print("func3()함수 실행")

def func4() :
    print("func4()함수 실행")

def func5() :
    print("func5()함수 실행")

func5() #실행할 함수


func5()함수 실행





#콘솔(console) : 키보드 + 모니터

#쓰기용 : 변수명 - open("파일명","w")

text = "통신응용프로그래밍실습"
f = open("e:\swa\swa2.txt","w")
f.write(text)   #write 함수
f.close()
print("파일저장 완료 : %s" %f)


파일저장 완료 : <_io.TextIOWrapper name='e:\\swa\\swa2.txt' mode='w' encoding='cp949'>


# Source_code 10-1
inFp = open("E:\swa\swa.txt","r",encoding="utf-8")
intStr = inFp.readline()
print(intStr, end="")


intStr = inFp.readline()
print(intStr, end="")


intStr = inFp.readline()
print(intStr, end="")

inFp.close()

손용호

밤새더니

학교와서

계속 잠만 자네 (세번째 줄까지만 출력)



# Source_code 10-2
# while 문에 의한 처리
inFp = None
inStr = ""

inFp = open("E:\swa\swa.txt","r",encoding="utf-8")
while True :
    inStr = inFp.readline()
    if inStr == "" :
        break
    print(inStr,end="")
inFp.close()

손용호

밤새더니

학교와서

쿨쿨자네

으이그



# Source_code 10-2
# list 문에 의한 처리
inFp = None
inList, inStr =[], ""

inFp = open("E:\swa\swa.txt","r",encoding="utf-8")
inList = inFp.readlines()
for inStr in inList :
    print(inStr,end="")
inFp.close()

손용호

밤새더니

학교와서

쿨쿨자네

으이그




#source_code10-6
#파일검색
import os
inFp = None
fName, inList, inStr = "",[],""
while True :
    fName = input("파일명을 입력하세요 : ")
    if os.path.exists(fName) :
        inFp = open("E:\swa\swa.txt","r",encoding="utf-8")
        inList = inFp.readlines()
        for inStr in inList :
            print(inStr,end="")
            inFp.close()
    if fName == "끝" :
        break
    if fName != "swa.txt" :
        print("%s 파일이 없습니다."%fName)
print("프로그램을 종료합니다.")


#source_code10-6
#파일쓰기
outFp = None
outStr = ""

outFp = open("E:\swa\swa2.txt","a",encoding="utf-8")
while True :
    outStr = input("내용 입력 : ")
    if outStr != "" :
        outFp.writelines(outStr+"\n")
    else :
        break
outFp.close()  
print("정상적으로 파일에 썼습니다.")