파이썬
파이썬
오후 10:39 1 - Colab
- : char,int,long,longlong, at,double..
x= 10
print("x : " "type:",type(x))
y=10.0
print("y : ",y,"type:",type(y))
#
z="10.0"
print("z : ", z,"type:",type(z))
# ( ) bool
is_suudent = True
is_adult = False
print("is_adult : ", is_adult,"type:",type(is_adult))
[c ] (long)a=10
-> 1. 2. [ ]
* *- -
#
x= 10
print("x : " "type:",type(x))
x= 10.0
print("x : " "type:",type(x))
#
x= 10
print("x : " "type:",type(x))
x= str(10)
print("x : " "type:",type(x))
->
#
a=10
b=3
print(a+b) #13
print(a-b) #7
print(a*b) #30-
print(a/b) #3:3333-
print(a%b) #1-
print(a//b)#3-
https://colab.research.google.com/drive/1gLBYfTQkmGzycwFlxiu0VSqdplGz5AqF#scrollTo=JO7d-2Fcf0b4&printMode=true 1/14
24. 11. 30. 오후 10:39 1 - Colab
#->
print(a**b) #1000
13
7
30
3.3333333333333335
1
3
1000
a=10
b=3.14
print(a)
print(b)
10
3.14
# desK
desk=a #a desk
a=b #a b
b=desk #b desk
print(a)
print(b)
3.14
10
# tE , )
#
c=0.082
d=1.414
print(c,d) #
c,d=d,c
print(c,d) #
0.082 1.414
1.414 0.082
- . , .
# : , , , , ,
a=10
b=100
print(a>=b)
print(a<=b)
print(a>b)
print(a<b)
print(a==b)
print(a!=b)
False
True
False
True
False
True
https://colab.research.google.com/drive/1gLBYfTQkmGzycwFlxiu0VSqdplGz5AqF#scrollTo=JO7d-2Fcf0b4&printMode=true 2/14
24. 11. 30. 오후 10:39 1 - Colab
# : and,or,not
cond1=10>5
cond2=1000<1
cond3=100==100.0
print(cond1)
print(cond2)
print(cond3)
True
False
True
#and : [ / ]
print(cond1 and cond2)
print(cond2 and cond1)
print(cond1 and cond3)
False
False
True
#or : ( ) [ / ]
print(cond1 or cond2)
print(cond2 or False)
print(cond1 or cond3)
True
False
True
#not : [ / ]
print(cond1, not cond1)
print(cond2, not cond2)
True False
False True
- print() - input()
- =input(" : ")
# -
hello=input(" :")
:234
num : type <class 'str'>
num=input(" : ")
print("num : ","type ",type(num))
- ,
: 13
num : type <class 'str'>
print(float(num)+10)
23.0
# [ ]
a= int(input(" : "))
b= int(input(" : "))
print(a+b) #
print(a-b) #
print(a/b) #
https://colab.research.google.com/drive/1gLBYfTQkmGzycwFlxiu0VSqdplGz5AqF#scrollTo=JO7d-2Fcf0b4&printMode=true 3/14
24. 11. 30. 오후 10:39 1 - Colab
print(a*b) #
print(a//b)#
print(a%b) #
print(a**0.5+b**0.5) #
print(a**2+b**2) #
print(a**b) #
: 2
: 4
6
-2
0.5
8
0
2
3.414213562373095
20
16
in
#
x=10
if x>5:
print("x 5 ")
x 5
x=int(input(" : ")) # ( )
if x>5:
print("x 5 ")
else:
print("x 5 ")
x=int(input(" : ")) # ( )
if x>5:
print("x 5 ")
elif x==5: # "=="
print("x 5 ")
else:
print("x 5 ")
#
x=15
if x>10:
if x<20:
print("x 10 20 ")
# and,or,not
x=15
if 10<x and x<20:
print("x 10 20 ")
x 10 20
#
x=3
if x>5: #
pass # ,
else:
print(" ")
https://colab.research.google.com/drive/1gLBYfTQkmGzycwFlxiu0VSqdplGz5AqF#scrollTo=JO7d-2Fcf0b4&printMode=true 4/14
24. 11. 30. 오후 10:39 1 - Colab
# :if-else
# if-else
x=10
result=0
if x>5:
result = ' '
else:
result=' '
print(result)
#in:
names=[" "," "," "]
for
range()
3 : (0) , , (1)
: ~ -1
for i in range(10):
print(i)
0
1
2
3
4
5
6
7
8
9
for i in range(1,11) :
print(i)
1
2
3
4
5
6
7
8
9
10
https://colab.research.google.com/drive/1gLBYfTQkmGzycwFlxiu0VSqdplGz5AqF#scrollTo=JO7d-2Fcf0b4&printMode=true 5/14
24. 11. 30. 오후 10:39 1 - Colab
if"3"in str(i):
" *
print("x", end=' ')end =
elif"6"in str(i):
:
1 2 x 4 5 x 7 8 x 10 11 12 x 14 15 x 17 18 x 20 21 22 x 24 25 x 27 28 x x x x x x x x x x x 40 41 42 x 44 45 x 47 48
for i in range(1,101) :
if"3"in str(i)or"6"in str(i)or"9"in str(i):
print("X", end =' ')
else:
print(i,end =' ')
1 2 X 4 5 X 7 8 X 10 11 12 X 14 15 X 17 18 X 20 21 22 X 24 25 X 27 28 X X X X X X X X X X X 40 41 42 X 44 45 X 47 48
1 2 X 4 5 X 7 8 X 10 11 12 X 14 15 X 17 18 X 20 21 22 X 24 25 X 27 28 X XX X X XX X X XX X X XX 40 41 42 X 44 45 X 47
for
(range, , ) [ ]
score_kor=[8,13,25] [ )
8
13
25
greeting = "hello" [ )
h
e
l
l
o
#1~10
for i in range(1,11,2): #( , , )
print(i)
1
3
5
7
https://colab.research.google.com/drive/1gLBYfTQkmGzycwFlxiu0VSqdplGz5AqF#scrollTo=JO7d-2Fcf0b4&printMode=true 6/14
24. 11. 30. 오후 10:39 1 - Colab
9
1
3
5
7
9
#1~10
for i in range(1,11):
if i%2==0: #%( ) ==( )
print(i)
for i in range(2,11,2): #( , , )
print(i)
2
4
6
8
10
2
4
6
8
10
while
n=5
while n>-5:
print(n)
n -=1 nr
5
4
3
2
1
0
-1
-2
-3
-4
break&continue
break :
continue : ,
for i in range(10):
if i==5:
break #break
print(i)
for i in range(10):
if i==5:
continue #break
print(i)
https://colab.research.google.com/drive/1gLBYfTQkmGzycwFlxiu0VSqdplGz5AqF#scrollTo=JO7d-2Fcf0b4&printMode=true 7/14
24. 11. 30. 오후 10:39 1 - Colab
#x 0~9 y 0~9
for x in range (0,10):
for y in range (0,10):
print(x,y,x*y)
.
append E
#1~10
a=[1,2,3,4,5,6,7,8,9,10]
print(a)
#(1)
b= [] #
for i in range(1,11):
b.append(i)
print(b)
[1]
[1, 2]
[1, 2, 3]
[1, 2, 3, 4]
[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6, 7]
[1, 2, 3, 4, 5, 6, 7, 8]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
#(2) - ,
c=[x for x in range(1,11)]
print (c)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
#(2) - ,
c=[x for x in range(1,11) if x%2==0]
print (c)
[2, 4, 6, 8, 10]
list
: ( )
: ( )
:
INDEX
https://colab.research.google.com/drive/1gLBYfTQkmGzycwFlxiu0VSqdplGz5AqF#scrollTo=JO7d-2Fcf0b4&printMode=true 8/14
24. 11. 30. 오후 10:39 1 - Colab
closet=[' ',' ',' ']
print(closet[0])
print(closet[1])
#
closet[1]= ' '
print(closet)
print(closet[1])
#
closet.append(' ')
print(closet)
#
closet.remove(' ')
print(closet)
#
closet=[' ', ' ', ' ', ' ']
print(len(closet))
#1~100
num=[]
for i in range(1,101):
num.append(i)
print(num)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 3
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 3
β : | ist ( range ]
num=list(range(1,101))
print(num)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 3
#1
sc=[40,50,60,70,80,80,70]
sc_sum=0
for s in sc:
sc_sum += s →
print(sc_sum/len(sc))
print(sc_sum) #
print(sum(sc)) #sc
64.28571428571429
450
450
https://colab.research.google.com/drive/1gLBYfTQkmGzycwFlxiu0VSqdplGz5AqF#scrollTo=JO7d-2Fcf0b4&printMode=true 9/14
24. 11. 30. 오후 10:39 1 - Colab
gr=[[1,2,3],[4,5,6],[7,8,9]]
print(gr)
print(gr[1])
print(gr[1][2])
1
2
3
4
5
6
7
8
9
https://drive.google.com/ le/d/1rQX0jT1XNdsZ2dzdjLDLwsgKClxVIZGC/view
Enter
(.append/.remove)
# 5
a=[1,2,3,4]
a.append(5)
print(a)
[1, 2, 3, 4, 5]
# 2
a=[1,2,3,4,5]
a.remove(2)
print(a)
[1, 3, 4, 5]
# 2 /
b=[1,2,3,2,4]
b.remove(2)
print(a)
[1, 3, 2, 4]
"
"
de π )
b=[1,2,3,2,4]
del b[1]
print(b)
[1, 3, 2, 4]
(sort)
, ,
https://colab.research.google.com/drive/1gLBYfTQkmGzycwFlxiu0VSqdplGz5AqF#scrollTo=JO7d-2Fcf0b4&printMode=true 10/14
24. 11. 30. 오후 10:39 1 - Colab
# :
temp=[3,6,7,2,5,9,1] . sort :
temp.sort() Sorte -
< ]
print(temp)
[1, 2, 3, 5, 6, 7, 9] .
revarge :
list ( rererged ( 1 ) :
# : ,
temp=[3,6,7,2,5,9,1]
print(sorted(temp))
print(temp)
[1, 2, 3, 5, 6, 7, 9]
[3, 6, 7, 2, 5, 9, 1]
#
e=[1,2,3,4,5]
e.reverse()
print(e)
[5, 4, 3, 2, 1]
#
e=[1,2,3,4,5]
print(list(reversed(e))) #range list,for
[5, 4, 3, 2, 1]
[ n :m ] (temp[1:3])
[ n :m :k ] (temp[1:3:2])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[2, 3, 4, 5, 6, 7, 8]
[2, 4, 6, 8]
#
- )
print(temp[::-1]) < - > ~ ( (*
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
: len()
100
1 O0 [ ow gg )
a
for i in range(len(temp)):
print(i ,end" ")
:insert( , )
https://colab.research.google.com/drive/1gLBYfTQkmGzycwFlxiu0VSqdplGz5AqF#scrollTo=JO7d-2Fcf0b4&printMode=true 11/14
24. 11. 30. 오후 10:39 1 - Colab
a=[" "," "," "," "]
print(a)
∞ [z3
a.insert(2," ")
print(a)
:extend()
#
a=[1,2,3]
b=[10,11,12]
print(a+b) →
print(a)
print(b)
#
a.extend(b)
print(a)
: count()
: list clear()
#
a=[1,2,3]
a.clear()
print(a)
[]
#
del a
print(a)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-66-db18b0bbee98> in <cell line: 3>()
1 #
2 del a
----> 3 print(a)
:copy()
: , [.copy()]
:
https://colab.research.google.com/drive/1gLBYfTQkmGzycwFlxiu0VSqdplGz5AqF#scrollTo=JO7d-2Fcf0b4&printMode=true 12/14
24. 11. 30. 오후 10:39 1 - Colab
#
import copy ⑧
a=[1,2,3] a sopu ( ) .
:
a_copy=a.copy()
( opy . deepcopy(
n
a_deepCopy = copy.deepcopy(a)
a.clear()
print(a)
print(a_copy)
print(a_deepCopy)
[]
[1, 2, 3]
[1, 2, 3]
def ( ) : [ ]
#
def add_number(x,y): # /
return x+y
print(add_number(5,8))
13
#
temp=[1,2,3,4,5]
total=0
for i in temp:
total += i
print(total) #for
#
#
I st π
def sum_list(list_input):
total=0
for i in list_input:
total += i
return total
15
temp = [1, 2, 3, 4, 5]
total = 0
for i in range(0, 5):
total += temp[i]
print(total)
15
# β
print(sum_list([1,2,3]))
list input
-
# (4 )
def greeting():
print(" !") X
greeting()
!
a=greeting()
print(a) #
!
None
https://colab.research.google.com/drive/1gLBYfTQkmGzycwFlxiu0VSqdplGz5AqF#scrollTo=JO7d-2Fcf0b4&printMode=true 13/14
24. 11. 30. 오후 10:39 1 - Colab
greeting() #
greeting(" ")
# : , 2
# , ,
def div_num(a,b):
temp0=a//b
temp1=a%b
temp2=a/b
return temp0,temp1,temp2
#
#
a = div_num(10, 3)
print(a)
a= div_num(10,3)
print(div_num(10,3)[0])
(3, 1, 3.3333333333333335)
3
( )
#1~n
def r_sum(n):
if n ==1: #
return 1
else:
return n + r_sum(n-1)
print(r_sum(5))
15
https://colab.research.google.com/drive/1gLBYfTQkmGzycwFlxiu0VSqdplGz5AqF#scrollTo=JO7d-2Fcf0b4&printMode=true 14/14
24. 11. 30. 오후 10:40 약수.ipynb - Colab
#for
n = int(input("n : ")) #
for i in range(1, n + 1): #for
if n % i == 0:
print(i, end=' ')
n : 20
1 2 4 5 10 20
#
def di(x):
temp=[]
for y in range(1, x + 1):
if x % y == 0:
temp.append(y)
return temp
print(di(30))
#for
n=3
for i in range(1,11):
print(n*i,end=' ')
3 6 9 12 15 18 21 24 27 30
#
def multiples(x):
result = []
for i in range(1,11):
result.append(x*i)
return result
print(multiples(10))
[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
#
a=divisor(24)
b=divisor(18)
print(set(a))
print(set(b))
print(set(a).intersection(set(b)))
print(set(a)&set(b)) #&:
print(max(set(a)&set(b)))
#
a = multiples(24)
b = multiples(18)
print(set(a))
print(set(b))
https://colab.research.google.com/drive/1y4IpXuEmVO3rzEF8nQ1meMLQHTBUOCK3#printMode=true 1/3
24. 11. 30. 오후 10:40 약수.ipynb - Colab
print(set(a).intersection(set(b))) #
print(min(set(a) & set(b))) # ( )
{96, 192, 72, 168, 48, 144, 240, 24, 120, 216}
{162, 36, 72, 108, 144, 18, 180, 54, 90, 126}
{72, 144}
72
1
,
n = int(input(" : "))
if n < 2:
print(False)
else:
temp = [i for i in range(1, n + 1) if n % i == 0] #
if len(divisors) == 2:
print(True)
else:
print(False)
: 30
False
def di(x):
temp=[]
for y in range(1, x + 1):
if x % y == 0:
temp.append(y)
if len(temp)==2 :
return True
else:
return False
print(di(2))
True
def de(n):
if n<2:
return False
a=divisor(n)
if len(a)==2:
return True
else:
return False
print(de(2))
True
#1~100
for i in range(1,101):
if prime(i):
print(i, end=' ')
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
https://colab.research.google.com/drive/1y4IpXuEmVO3rzEF8nQ1meMLQHTBUOCK3#printMode=true 2/3
24. 11. 30. 오후 10:43 20241113 업다운 - Colab
Up-Down Game
1~100 ,
," "" "" !"
RANDOM
import random
random.randint( , ): ~
import random
a=random.randint(1,100)
print(a)
a=random.randint(1,100)
while True:
ans = int(input(" : "))
if ans > a:
print(" ")
elif ans < a:
print(" ")
else:
print(" !")
break
#
print(a)
while True:
ans=int(input(" 1, 0, -1"))
if ans==1:
a-=1
print(a)
elif ans==-1:
a+=1
print(a)
else:
print(" %d" % a)
break
#
a=random.randint(1,100)
while ans != a:
if a>ans:
print(" ")
ans=int(input(" : "))
elif ans > a:
print(" ")
ans=int(input(" : "))
print(" !")
https://colab.research.google.com/drive/14OL15qSKiYxO0YHhY23sUN-xdjIELLep#scrollTo=a5sGnr_D-9jG&printMode=true 1/2
24. 11. 30. 오후 10:41 거북이 프로그램.ipynb - Colab
t.initializeTurtle() #
#
t.initializeTurtle()
for i in range(3):
t.forward(100)
t.right(120)
t.initializeTurtle()
i=0
while i<3:
t.forward(100)
t.right(120)
i+=1
#
t.initializeTurtle()
for i in range(4):
t.forward(100)
t.right(90)
#
for i in range(2):
t.forward(100)
t.right(90)
t.forward(150)
t.right(90)
# 150, 100
for i in range(4):
if i%2==0: t.forward(100)
else: t.forward(150)
t.right(90)
Enter
#
t.initializeTurtle()
for i in range(5):
t.forward(100)
t.right(72)
#
t.initializeTurtle()
for i in range(6):
t.forward(100)
t.right(60)
# 360
# =120
# =90
# =72
#n =360/n
t.initializeTurtle()
n=int(input(" n :"))
for i in range(n):
t.forward(10)
t.right(360/n)
https://colab.research.google.com/drive/14z7q8_56ltEWnedchTx8dv8q2QzEVUIG#scrollTo=AyESumi9_huV&printMode=true 1/2
24. 11. 30. 오후 10:41 거북이 프로그램.ipynb - Colab
# ( )
t.initializeTurtle()
n=int(input(" n :"))
def shape(n):
for i in range(n):
t.forward(50)
t.right(360/n)
shape(n)
#
t.initializeTurtle()
t.circle(50)
https://colab.research.google.com/drive/14z7q8_56ltEWnedchTx8dv8q2QzEVUIG#scrollTo=AyESumi9_huV&printMode=true 2/2