4+3
a=1
b=2
c=a+b
print("hello")
print(c)
a=int(input())
b=int(input())
result=a+b
print(a,"+",b,"=",result)




print(100+100)
print("%d",(100+100))
print("%d"%(100+100))
print("%d %d"%(100,100))

서식->%d(10진수),%x(16진수),%f(실수),%(문자),%s(문자열)



def fun_ex(num):
    n=1
    while n <=10:
        print(n,"x",num,"=",n*num)

fun_ex(숫자입력)

1 x 20 = 20

2 x 20 = 40

3 x 20 = 60

4 x 20 = 80

5 x 20 = 100

6 x 20 = 120

7 x 20 = 140

8 x 20 = 160

9 x 20 = 180

10 x 20 = 200



import time
n=1
while n < 9:
    m=1
    print(n+1,"단")
    n=n+1
    while m <= 9:
        print(n,"x",m,"=",n*m)
        m=m+1
    time.sleep(3)

8월23일자 구구단



i,k = 0,0
for i in range(2,10):
    print("--- %d 단 ---"%i)
    for k in range(1,10):
        guguLine = str("%2d X %2d = %2d"%(i,k,i*k))
        print(guguLine)

8월30일자 구구단



from tkinter import*

##변수##
window = None
canvas = None

x1, y1, x2, y2 = None, None, None, None

## 함수 ##
def mouseClick(event):
    global x1, y1, x2, y2
    x1 = event.x
    y1 = event.y
    
def mouseDrop(event):
    global x1, y1, x2, y2
    x2 = event.x
    y2 = event.y
    canvas.create_line(x1,y1,x2,y2,width=5,fill="red")

## 메인코드 ##
window = Tk()
window.title("그림그리기")
canvas = Canvas(window, height=300, width=300)
canvas.bind("",mouseClick)
canvas.bind("",mouseDrop)
canvas.pack()
window.mainloop()

0823 그림판

'먼지 낀 책장사이 > Python' 카테고리의 다른 글

쓰레드  (0) 2016.10.11
상속, 오버라이딩, 툴킷  (0) 2016.09.27
Raw파일 읽기, 클래스, 생성자  (0) 2016.09.20
가변 매개변수, 모듈  (0) 2016.09.06
연산자, while 반복, for문, 리스트/사전/튜플  (0) 2016.08.30

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("정상적으로 파일에 썼습니다.")









8>>1
8<<1
2&4    #and
2|4    #or
8^2    #ex or
~0



score = 1
while score != 0:
	score=int(input("점수입력 : "))
	if score>=90:
		print("A")
	elif score>=80:
		print("B")
	elif score>=70:
		print("C")
	elif score>=60:
		print("D")
	else:
		print("F")
	print("학점입니다.^^\n")
print("프로그램을 종료합니다")











score = 1
while True :
        score=int(input("점수입력 : "))
        if score == 0 :
                break
        if score>=90 :
                print("A")
        elif score>=80:
                print("B")
        elif score>=70:
                print("C")
        elif score>=60:
                print("D")
        else:
                print("F")
        print("학점입니다.^^\n")
print("프로그램을 종료합니다")













for i in range(0,3,1):             #0으로 시작해서 3사이에 1씩
    print("Hello")
Hello
Hello
Hello
for i in [0,3,1]:                  #0으로 시작해서 3사이에 1씩
    print("Hello")
Hello
Hello
Hello
for i in range(0,6,1):             #0으로 시작해서 6사이에 1씩
    print("%d"%i)                  #"십진수의 형태로" i 값을 불러온다
0
1
2
3
4
5
for i in [0,1,2,3,4,5,6,7,8,9]:    #배열지정
    print("%d"%i)nbsp;             #"십진수의 형태로" i 값을 불러온다
0
1
2
3
4
5
6
7
8
9
i,hap = 0,0
for i in range(1,11,1):
    hap=hap+i
    print("1에서 %d 까지의 합 = %d"%(i,hap))
1에서 1 까지의 합 = 1
1에서 2 까지의 합 = 3
1에서 3 까지의 합 = 6
1에서 4 까지의 합 = 10
1에서 5 까지의 합 = 15
1에서 6 까지의 합 = 21
1에서 7 까지의 합 = 28
1에서 8 까지의 합 = 36
1에서 9 까지의 합 = 45
1에서 10 까지의 합 = 55









num = 1
while True:
    num = int(input("num : "))
    if num == 0:
                  break
    if num == 1:
                  print("다시 입력")
                  continue
    print(num)
    print("0이면 종료")










import random
my_tuple = ("one","two","three","four")
while True:
    i=random.randint(0,3)
    print(my_tuple[i])
    key = int(input("key : "))
    if key == 0:
        break
print("프로그램 종료")

대괄호로 묶으면 리스트 중괄호로 묶으면 사전 소괄호로 묶으면 튜플




import random
i=0
key=1
my_list = ["one","two","three","four"]
while True:
    i=random.randint(0,3)
    print(my_list[i])
    key = int(input("key : "))
    if key == 0:
        break
print("프로그램 종료")

대괄호로 묶으면 리스트 중괄호로 묶으면 사전 소괄호로 묶으면 튜플


list값 변경

a_list = [10,20,30,40]

a_list [2] = 300


list값 삭제

a_list = [10,20,30,40]

del(a_list[1])


dictionary

dic_1 = {1:'a',2:'b',3:'c'}


student = {'학번':1000,'이름':'홍길동','학과':'모바일'}


dictionary값 추가/변경

student ['연락처']='010-9406-2682'


dictionary값 삭제

del(student[연락처])



데이터 읽기

student['학번']

list(student.keys())

student.values()

student.items()



#for문 활용 dictionary값 출력
mobile={}   #tuple->().list->[]
mobile['이름']='김수환'
mobile['학번']='130100682'
mobile['주소']='서울 용산구 보광동'
mobile['학점']='A+'
mobile['전화번호']='010-1234-5678'
for mo in mobile.keys():
    print('%s ---> %s' %(mo,mobile[mo]))




#함수정의
def calc(num1,num2,op):
    result = 0
    if op == '+' :
        result = num1 + num2
    if op == '-' :
        result = num1 - num2
    if op == '*' :
        result = num1 * num2
    if op == '/' :
        result = num1 / num2
    return result

##변수선언
res = 0
var1, var2, oper = 0, 0, ""

###메인코드
#res = calc(10,20,"+")
print(res)
print()
oper = input("연산자 입력(+,-,*,/) : ")
var1 = int(input("num1 값 입력 : "))
var2 = int(input("num2 값 입력 : "))

res = calc(var1,var2,oper)
print("계산기 : %d %s %d = %f "%(var1,oper,var2,res))


def para_func(val_1=0,val_2=0,val_3=0,val_4=0,val_5=0):    #매개변수
    result = 0
    result = val_1+val_2+val_3+val_4+val_5
    return result
value = para_func(10,20,30,40,50)
print(value)
150

para_func(10,20,30)

60


#함수의 가변 매개변수
def para_func(*para):
    result = 0
    for num in para:
        result = result + num
    return result
hap = para_func(10,20,30)
print(hap)


'먼지 낀 책장사이 > Python' 카테고리의 다른 글

쓰레드  (0) 2016.10.11
상속, 오버라이딩, 툴킷  (0) 2016.09.27
Raw파일 읽기, 클래스, 생성자  (0) 2016.09.20
문자열, 구구단, 그림그리기  (0) 2016.09.13
가변 매개변수, 모듈  (0) 2016.09.06