[With The Wiener] ¿©±â´Â ¹Ì·¡ÀÇ ITÀ¶ÇÕÀÎÀç°¡ °øºÎÇÏ´Â °ø°£ÀÔ´Ï´Ù.



<[python]>


[±âº»°úÁ¤, 1´Ü°è]

ÀÚ! ÀÌÁ¦ ½ÃÀÛÇÕ´Ï´Ù ^^

1. ÀÔ·ÂÇϱâ

<ÇÁ·Î±×·¥-1>

a=input("age:")
print a
b=raw_input("who are you")
print a, "+", b


2. if¹®

<ÇÁ·Î±×·¥-1>

g=raw_input("hag?")
if g=='A':
    message="ok"
    print message
elif g=='B':
    message="why"
    print message
elif g=='C':
    message="go home"
    print message
else:
    print "study" 

<ÇÁ·Î±×·¥-2>

age = input("age:")

if age<=19:
    print "haha"
elif age <=30:
    print "go"
elif age <=50:
    print "home"
else:
    print "mi" 


3. ÇÔ¼ö ¸¸µé±â-1

<ÇÁ·Î±×·¥-1>

def greet():
    print "good moring"

print "hi!"
greet()

def greet(msg):
    print msg

def plus(x, y):
    print x + y
    
print "hi!"
greet("good moring")
plus(3,5)


4. ÇÔ¼ö ¸¸µé±â-2

<ÇÁ·Î±×·¥-1>

def switch(a,b):
    t=a
    a=b
    b=t
    print "t2=",a,",",b
    
a=raw_input("a:")
b=raw_input("b:")
print "t1=",a,",",b
switch(a,b)
print "t3=",a,",",b 

def mi(x,y):
    z=x-y
    return z

def ma(x,y):
    z=x+y
    return z
    
a=7
b=6

print mi(a,b)
print ma(a,b)


5. ÇÔ¼ö ¸¸µé±â-3

<ÇÁ·Î±×·¥-1>

def fin(a,b,c):
    max=min=a
    if max < b:
        max=b
    elif max b:
        min=b
    elif min >c:
        min=c
        
    return [max, min]

x=input("x:")
y=input("y:")
z=input("z:")

m=fin(x,y,z)
print m[0], ",", m[1]


6. ¹è¿­

<ÇÁ·Î±×·¥-1>

p=['010', '333', '5555']
print "phone", p[0], "+", p[1], "+", p[2]

c=[1,2,3,4]
print "num", c[3]
print abs(3-5)

def average(slist):
    return (int(slist[0])+int(slist[1])+int(slist[2]))/3
    
s=raw_input("3 num:")
sl = s.split()

avg=average(sl)

if (avg >=60):
    print "ok!"
else :
    print "go home"


7. ¹Ýº¹¹®

<ÇÁ·Î±×·¥-1>

for i in[57,333,9]:
    print i

ih=[1,2,3,4]
for i in ih:
    print i

for i in range(1,31):
    print i

for i in range(2, 9):
    for j in range(1, 9):
        print i,"*",j,"=", i*j
    
k=3
while k>0:
    print k
    k=k-1


8. Àç±ÍÇÔ¼ö

<ÇÁ·Î±×·¥-1>

#n!

def f(n):
    if n ==1:    return 1
    return n*f(n-1)

p=input("n:")
k = f(p)
print k

#hanoi

def h(s,e,p):
    if p <=0: return 0;
    
    k=6-(s+e)
    h(s,k,p-1)
    print s,",",e,",",p
    h(k,e,p-1)
    
n=input("n:")
h(1,3,n) 


9. ÆÄÀÏó¸®

<ÇÁ·Î±×·¥-1>

tt=open('input.txt','r')
ss=tf.readlines()
tf.flush()
tf.close()
print (ss)

tf=open('input.txt','r')
ss=tf.readlines()
tf.flush()
tf.close()
print (ss[1])

tf=open('input.txt','r')
ss=tf.readline()
tf.flush()
tf.close()
print ss


tf=open('input.txt','w')
tf.write('babo\n')
tf.close()


10. class

<ÇÁ·Î±×·¥-1>

class Pp:
    name = "hong gil dong"
    def Print(self):
        print("my name is {0}".format(self.name))

p1 = Pp()
p1.Print()

class Pp:
    name = "bobo indi"

p1=Pp()
p2=Pp()
print("hahah",p1.name)
print("hoho",p2.name)


11. »ó¼Ó

<ÇÁ·Î±×·¥-1>

class Super:
    x=10
    def printx(self):
        print(self.x)

class Sub(Super):
    y=20
    def printy(self):
        print(self.y)
        
s = Sub()
s.a=30

print("s:",s.__dict__) 


12. 1Â÷¿ø¹è¿­

<ÇÁ·Î±×·¥-1>


for j in range(0,4):
    line=raw_input()
    slist = line.split()

    n = len(slist)
    for i in range(0,n):
        print slist[i],
    print
    
  

<ÇÁ·Î±×·¥-2>

n=5
for i in range(1, n):
    print i,
print

s=raw_input();

for i in range(0,5):
    print s[i],
print

13. 2Â÷¿ø¹è¿­

<ÇÁ·Î±×·¥-1>


t = [[0 for col in range(4)] for row in range(4)]

for i in range(0, 4):
    for j in range(0, 4):
        t[i][j] = i*j

for i in range(0, 4):
    for j in range(0, 4):
        print t[i][j],
    print


14. sql(creat)

<ÇÁ·Î±×·¥-1>

import sqlite3

def creat_table():
    conn=sqlite3.connect('my_books.db')
    cur=conn.cursor()
    
    cur.execute('''CREATE TABLE my_books(
                        title text,
                        published_date text,
                        publisher text,
                        pages integer,
                        recommenndation integer
                    )'''
    )
    
    conn.commit()
    conn.close()
    
creat_table() 

15. sql(insert)

<ÇÁ·Î±×·¥-1>

import sqlite3

def insert_books():
    conn=sqlite3.connect('my_books.db')
    cur=conn.cursor()
    
    cur.execute("INSERT INTO my_books VALUES('haha01', '2013.04.28', 'A',200,0)")
    cur.execute("INSERT INTO my_books VALUES('haha02', '2016.04.28', 'A',500,0)")
    cur.execute("INSERT INTO my_books VALUES('haha03', '2016.04.30', 'B',500,0)")
    
    insert_sql = 'INSERT INTO my_books VALUES(?, ?, ?, ?, ?)'
    cur.execute(insert_sql, ('code02', '2010.03.04','B',584,1))
    
    conn.commit()
    conn.close()
    
insert_books() 


16. sql(select)

<ÇÁ·Î±×·¥-1>

import sqlite3

def select_all_books():
    conn = sqlite3.connect('my_books.db')
    cur=conn.cursor()
    cur.execute('SELECT * FROM my_books')
    
    print('1. all data slect')
    books = cur.fetchall()
    for book in books:
        print(book)
    conn.close()

select_all_books()
print

<ÇÁ·Î±×·¥-2>

import sqlite3

def select_some_books(number):
    conn = sqlite3.connect('my_books.db')
    cur=conn.cursor()
    cur.execute('SELECT * FROM my_books')
    
    print('2. some data slecte')
    books = cur.fetchmany(number)
    
    for book in books:
        print(book)
        
    conn.close()

select_some_books(3)
print

<ÇÁ·Î±×·¥-3>

import sqlite3

def select_one_books():
    conn = sqlite3.connect('my_books.db')
    cur=conn.cursor()
    cur.execute('SELECT * FROM my_books')
    
    print('3. one data slect')
    print(cur.fetchone())
        
    conn.close()
    
select_one_books()
print 


17. sql(update)

<ÇÁ·Î±×·¥-1>

import sqlite3

def select_all_books():
    conn = sqlite3.connect('my_books.db')
    cur=conn.cursor()
    cur.execute('SELECT * FROM my_books')
    
    print('1. all data slect')
    books = cur.fetchall()
    for book in books:
        print(book)
    conn.close()
    
def update_books():
    conn = sqlite3.connect('my_books.db')
    cur=conn.cursor()
    update_sql='UPDATE my_books SET recommenndation=? WHERE title=?'
    cur.execute(update_sql, (6, 'haha01'))
        
    conn.commit()
    conn.close()
    
select_all_books()
update_books()
print('ok')
select_all_books()


18. sql(delete)

<ÇÁ·Î±×·¥-1>

import sqlite3

def select_all_books():
    conn = sqlite3.connect('my_books.db')
    cur=conn.cursor()
    cur.execute('SELECT * FROM my_books')
    
    print('1. all data slect')
    books = cur.fetchall()
    for book in books:
        print(book)
    conn.close()

def delete_books():
    conn = sqlite3.connect('my_books.db')
    cur=conn.cursor()
    
    delete_sql='DELETE FROM my_books WHERE publisher=?'
    cur.execute(delete_sql, 'A')
    
    conn.commit()
    conn.close()
    
select_all_books()
delete_books()
print ('ok')
select_all_books() 


19. pygame(񃧯)

<ÇÁ·Î±×·¥-1>

import pygame, sys
import random
from pygame.locals import *

pygame.init()
DISPLAYSURF = pygame.display.set_mode((800,400))
pygame.display.set_caption('Wiener World')

while 1:
 for event in pygame.event.get():
  if event.type == QUIT:
   pygame.quit()
   sys.exit()
  pygame.display.update()



20. pygame(µµÇü¸¸µé±â)

<ÇÁ·Î±×·¥-1>

import pygame, sys
from pygame.locals import *

pygame.init()
DISPLAYSURF = pygame.display.set_mode((600,500),0,32)
pygame.display.set_caption('Wiener World')

BLACK = (0, 0, 0)
WHITE = (255,255,255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0,0,255)

DISPLAYSURF.fill(WHITE) 
pygame.draw.polygon(DISPLAYSURF, GREEN, ((146, 0), (291,106), (236,277), (56, 277), (0, 106)))
pygame.draw.line(DISPLAYSURF, BLUE, (60, 60), (120, 60), 4)
pygame.draw.line(DISPLAYSURF, BLUE, (120, 60), (60, 120))
pygame.draw.line(DISPLAYSURF, BLUE, (60, 120), (120, 120), 8)
pygame.draw.circle(DISPLAYSURF, BLUE, (300, 50), 50, 0)
pygame.draw.ellipse(DISPLAYSURF, RED, (300, 200, 40, 80), 1)
pygame.draw.rect(DISPLAYSURF, RED, (200, 150, 100, 50))

pixObj = pygame.PixelArray(DISPLAYSURF)
pixObj[380][280] = BLACK
pixObj[382][282] = BLACK
pixObj[384][284] = BLACK
pixObj[386][286] = BLACK
pixObj[388][288] = BLACK
del pixObj

while 1:
 for event in pygame.event.get():
  if event.type == QUIT:
   pygame.quit()
   sys.exit()
  pygame.display.update()


21. pygame(¾Ë¾Æ¼­ ¿òÁ÷ÀÌ´Â °´Ã¼)

<ÇÁ·Î±×·¥-1>

import pygame, sys
from pygame.locals import *

pygame.init()

FPS = 30
fpsClock = pygame.time.Clock()

DISPLAYSURF = pygame.display.set_mode((1500, 1000), 0, 32)
pygame.display.set_caption('Animation')

WHITE = (255, 255, 255)
catImg = pygame.image.load('cat.png')
catx = 10
caty = 10
direction = 'right'

while 1:
 DISPLAYSURF.fill(WHITE)

 if direction == 'right':
  catx += 5
  if catx == 750:
   direction = 'rightdown'
 elif direction =='rightdown':
  caty += 5
  catx += 5
  if catx == 1000:
   direction = 'down'
 elif direction =='down':
  caty += 5
  if caty == 600:
   direction = 'leftdown'
 elif direction =='leftdown':
  caty += 5
  catx -= 5
  if caty == 900:
   direction = 'left'
 elif direction =='left':
  catx -= 5
  if catx == 250:
   direction = 'leftup'
 elif direction =='leftup':
  caty -= 5
  catx -= 5
  if catx == 10:
   direction = 'up'
 elif direction =='up':
  caty -= 5
  if caty == 150:
   direction = 'rightup'
 elif direction =='rightup':
  catx += 5
  caty -= 5
  if caty == 10:
   direction = 'right'

 
 DISPLAYSURF.blit(catImg, (catx, caty))
  
 for event in pygame.event.get():
  if event.type == QUIT:
   pygame.quit()
   sys.exit()
 pygame.display.update()
 fpsClock.tick(FPS)


¿©±â±îÁö ¿À¼Ì±º¿ä!~

À̰÷Àº 'À§³Ê(Wiener)' ÀÔ´Ï´Ù.

°¨»çÇÕ´Ï´Ù ^^

*

Counter : 2888

Copyright ¨Ï wiener2020.cafe24.com(wiener) All rights reserved