def print_address() :
print('°æ»óºÏµµ')
print('¿ï¸ª±º ¿ï¸ªÀ¾')
print('µ¶µµ¸® »ê 1-96¹øÁö')
print_address() # Á¤ÀÇÇÑ ÇÔ¼ö¸¦ È£Ãâ
print('°æ»óºÏµµ')
print('¿ï¸ª±º ¿ï¸ªÀ¾')
print('µ¶µµ¸® »ê 1-96¹øÁö')
print_address()
print_address()
print_address()
def print_address(name):
print("¼¿ï Ưº°½Ã Á¾·Î±¸ 1¹øÁö")
print("ÆÄÀ̽㠺ôµù 7Ãþ")
print(name)
print_address("È«±æµ¿")
def calculate_area(radius):
area = 3.14 * radius**2
return area # ÀÌÀü ÁÙ¿¡¼ ±¸ÇÑ area °ªÀ» È£Ãâ¹®¿¡ µ¹·ÁÁØ´Ù
c_area = calculate_area(5.0) # calculate_are() ÇÔ¼ö°¡ °è»êÇÑ °ªÀ» c_area¿¡ ÀúÀå
print(calculate_area (5.0))
area_sum = calculate_area(5.0) + calculate_area(10.0)
print(area_sum)
calculate_area(10.0) # ÇÔ¼ö¸¦ È£Ã⸸ ÇÏ°í ±× ¹Ýȯ°ªÀ» »ç¿ë¾ÈÇÔ
def sort_num(n1, n2): # 2°³ÀÇ °ªÀ» ¹Þ¾Æ¿À´Â ÇÔ¼ö
if n1 < n2:
return n1, n2 # n1ÀÌ ´õ ÀÛÀ¸¸é n1, n2 ¼ø¼·Î ¹Ýȯ
else:
return n2, n1 # n2°¡ ´õ ÀÛÀ¸¸é n2, n1 ¼ø¼·Î ¹Ýȯ
print(sort_num(110, 210)) # 110°ú 210À» ÇÔ¼öÀÇ ÀÎÀÚ·Î Àü´ÞÇÏ°í ¹ÝȯµÇ´Â °ªÀ» Ãâ·Â
print(sort_num(2100, 80))
def calc(n1, n2):
return n1 + n2, n1 - n2, n1 * n2, n1 / n2 # µ¡¼À, »¬¼À, °ö¼À, ³ª´°¼À °á°ú¸¦ ¹Ýȯ
n1, n2 = 200, 100
t1, t2, t3, t4 = calc(n1, n2) # ³× °³ÀÇ °ªÀ» ¹Ýȯ¹Þ±â À§ÇØ 4°³ÀÇ º¯¼ö¸¦ »ç¿ëÇÔ
print(n1, '+', n2, '=', t1)
print(n1, '-', n2, '=', t2)
print(n1, '*', n2, '=', t3)
print(n1, '/', n2, '=', t4)
def get_sum(start, end): # start, end¸¦ ¸Å°³º¯¼ö·ÎÇÏ¿© ÀÎÀÚ¸¦ ¹Þ´Â´Ù
s = 0
for i in range(start, end+1): # startºÎÅÍ end±îÁö Á¤¼öÀÇ ÇÕÀ» ±¸ÇÔ
s += i
return s # startºÎÅÍ end±îÁö ¼öÀÇ ÇÕÀ» ¹ÝȯÇÑ´Ù
print(get_sum(1, 10)) # 1¿¡¼ 10±îÁö Á¤¼öÀÇ ÇÕ 55¸¦ Ãâ·ÂÇÑ´Ù
x = get_sum(1, 10) # 1°ú 10ÀÌ get_sum()ÀÇ ÀÎÀÚ°¡ µÈ´Ù.
print('x =', x)
y = get_sum(1, 20) # 1°ú 20ÀÌ get_sum()ÀÇ ÀÎÀÚ°¡ µÈ´Ù.
print('y =', y)
import turtle
t = turtle.Turtle()
t.shape("turtle")
def square(length): # length´Â ÇѺ¯ÀÇ ±æÀÌ
for i in range(4):
t.forward(length)
t.left(90)
square(100) # square() ÇÔ¼ö¸¦ È£ÃâÇÑ´Ù.
square(200) # È£Ãâ½Ã ÀÎÀÚ°ªÀ» 100, 200, 300À¸·Î ´Ù¸£°Ô ÇÑ´Ù
square(300)
turtle.done()
try:
turtle.bye()
except:
print("bye")
import turtle
t = turtle.Turtle()
# n-°¢ÇüÀ» ±×¸®´Â ÇÔ¼ö¸¦ Á¤ÀÇÇÑ´Ù.
def n_polygon(n, length):
for i in range(n):
t.forward(length)
t.left(360//n) # Á¤¼ö ³ª´°¼ÀÀº //À¸·Î ÇÑ´Ù.
for i in range(10):
t.left(20)
n_polygon(6, 100)
turtle.done()
try:
turtle.bye()
except:
print("bye")
def print_counter():
print('counter =', counter) # ÇÔ¼ö ³»ºÎÀÇ counter °ª
counter = 100
print_counter()
print('counter =', counter) # ÇÔ¼ö ¿ÜºÎÀÇ counter °ª
def print_counter():
counter = 200
print('counter =', counter) # ÇÔ¼ö ³»ºÎÀÇ counter °ª
counter = 100
print_counter()
print('counter =', counter) # ÇÔ¼ö ¿ÜºÎÀÇ counter °ª
def print_counter():
global counter # ÇÔ¼ö ¿ÜºÎÀÇ Àü¿ªº¯¼ö counter¸¦ »ç¿ëÇÏ°Ú´Ù´Â ¼±¾ð
counter = 200
print('counter =', counter) # ÇÔ¼ö ³»ºÎÀÇ counter °ª
counter = 100
print_counter()
print('counter =', counter) # ÇÔ¼ö ¿ÜºÎÀÇ counter °ª
def calculate_area(radius):
global area
area = 3.14 * radius**2
return
area = 0
r = float(input("¿øÀÇ ¹ÝÁö¸§: "))
calculate_area(r)
print(area)
def greet(name, msg):
print("¾È³ç", name + ', ' + msg)
greet("ö¼ö", "ÁÁÀº ¾Æħ!")
greet("¿µÈñ") # ÀÎÀÚ¸¦ 1°³¸¸ Àü´ÞÇÏ¿© greet()À» È£ÃâÇÔ
def greet(name, msg="º°ÀϾøÁÒ?"):
print("¾È³ç", name + ', ' + msg)
greet("¿µÈñ")
greet("ö¼ö")
greet("¹Î¼ö", "Àß Áö³»°í ÀÖÀ¸½ÃÁÒ?")
def power(base, exponent):
return base**exponent # base°¡ ¹ØÀÌ°í, exponent°¡ Áö¼ö°ªÀÌ´Ù.
power(2, 10) # 2ÀÇ 10½ÂÀ» ¹ÝȯÇÑ´Ù
power(10, 2) # 10ÀÇ 2½ÂÀ» ¹ÝȯÇÑ´Ù
power(base=2, exponent=10) # 2ÀÇ 10½ÂÀ» ¹ÝȯÇÑ´Ù
power(exponent=10, base=2) # 2ÀÇ 10½ÂÀ» ¹ÝȯÇÑ´Ù
power(base = 10, 2)
def weeklyPay(rate, hour):
if (hour > 30):
money = rate*30 + 1.5*rate*(hour-30)
else:
money = rate*hour
return money
r = int(input("½Ã±ÞÀ» ÀÔ·ÂÇϽÿÀ: ")) # ½Ã±ÞÀԷ¹ޱâ
h = int(input("±Ù¹« ½Ã°£À» ÀÔ·ÂÇϽÿÀ: ")) # ±Ù¹«½Ã°£ ÀԷ¹ޱâ
print("ÁÖ±ÞÀº " + str(weeklyPay(rate = r, hour = h)))
def getMinMax(mylist, method = 'max'):
minValue = 999999999999999999999999999999999
maxValue = -minValue
if method == 'max' :
for value in mylist:
if value > maxValue:
maxValue = value;
return maxValue
elif method == 'min' :
for value in mylist:
if value < minValue:
minValue = value;
return minValue
else :
print('illegal method')
list_data = [27, 90, 30, 87, 56]
i=0
while(True) :
print(list_data)
method_input = input('ÃÖ´ë°ªÀ» ¿øÇϸé max, ÃÖ¼Ò°ªÀ» ¿øÇϸé minÀ» ÀÔ·ÂÇϽÿÀ: ')
print(getMinMax(list_data, method_input))
i+=1
if(i==4):
break
import turtle
def drawBar(height):
t.begin_fill()
t.left(90)
t.forward(height)
t.write(str(height), font = ('Times New Roman', 16, 'bold'))
t.right(90)
t.forward(40)
t.right(90)
t.forward(height)
t.left(90)
t.end_fill()
data = [120, 56, 309, 220, 156, 23, 98]
t = turtle.Turtle()
t.color("blue")
t.fillcolor("red")
t.pensize(3)
for d in data:
drawBar(d)
turtle.done()
try:
turtle.bye()
except:
print("bye")
import turtle
t = turtle.Turtle()
t.shape("turtle")
t.speed(0)
def f(x):
return x**2 + 1
t.goto(200, 0)
t.goto(0, 0)
t.goto(0, 200)
t.goto(0, 0)
for x in range(150):
t.goto(x, int(0.01*f(x)))
turtle.done()
try:
turtle.bye()
except:
print("bye")
def factorial(n): # n!ÀÇ Àç±ÍÀû ±¸Çö
if n <= 1 : # Á¾·á Á¶°ÇÀÌ ¹Ýµå½Ã ÇÊ¿äÇÏ´Ù
return 1
else :
return n * factorial(n-1) # n * (n-1)! Á¤ÀÇ¿¡ µû¸¥ ±¸Çö
print('4! = ', factorial(4)) # ÀÎÀÚ·Î 4¸¦ ³Ö¾î È£Ãâ
def fibonacci(n):
if n<0: # ÀÔ·Â ¿À·ù °Ë»ç
print("À߸øµÈ ÀÔ·ÂÀÔ´Ï´Ù.")
elif n==1: # Àç±ÍÈ£Ãâ Áß´Ü Á¶°Ç
return 0
elif n==2: # Àç±ÍÈ£Ãâ Áß´Ü Á¶°Ç
return 1
else:
return fibonacci(n-1) + fibonacci(n-2) # Àç±ÍÈ£Ãâ
i = int(input("¸î ¹ø° Ç×: "))
print(fibonacci(i))
import datetime # ³¯Â¥¿Í ½Ã°£À» ´Ù·ç´Â ¸ðµâ
datetime.datetime.now()
today = datetime.date.today()
print(today)
today
today.year
today.month
today.day
# filename: my_func.py
def mf_print(msg, n = 1) :
print(msg * n)
# filename: main.py
import my_func
my_func.mf_print("my_func was imported ", 3) # my_func ¸ðµâÀÇ mf_print() ÇÔ¼ö È£Ãâ
# filename: main.py
import my_func as mf
mf.mf_print('[alias]', 5) # mf¶ó´Â º°¸íÀ» »ç¿ëÇؼ ¸Þ½ÃÁö¸¦ 5ȸ ¹Ýº¹Ãâ·Â
# filename: main.py
from my_func import mf_print
mf_print('-no module name-', 2) # mf_print()¸¦ È£ÃâÇÒ ¶§ my_func.À» »ç¿ë¾ÈÇصµ µÊ
# filename: main.py
from my_func import *
mf_print('-no module name-', 2)