height = 178.9 # float ŸÀÔÀÇ µ¥ÀÌÅ͸¦ ÀúÀåÇÑ´Ù.
height1 = 178.9 # float ŸÀÔÀÇ µ¥ÀÌÅ͸¦ ÀúÀåÇÑ´Ù.
height2 = 173.5 # float ŸÀÔÀÇ µ¥ÀÌÅ͸¦ ÀúÀåÇÑ´Ù.
height3 = 166.1 # float ŸÀÔÀÇ µ¥ÀÌÅ͸¦ ÀúÀåÇÑ´Ù.
height4 = 164.3 # float ŸÀÔÀÇ µ¥ÀÌÅ͸¦ ÀúÀåÇÑ´Ù.
height5 = 176.4 # float ŸÀÔÀÇ µ¥ÀÌÅ͸¦ ÀúÀåÇÑ´Ù.
heights = [178.9, 173.5, 166.1, 164.3, 176.4]
heights
7.2 ¿©·¯°³ÀÇ Ç׸ñÀÌ µé¾î°¡´Â ¸®½ºÆ®¸¦ ¸¸µéÀÚ
bts = ['V', 'Jungkook', 'Jimin']
bts = []
bts = []
bts.append("V")
bts
bts.append("Jin")
bts.append("Suga")
bts
bts = ['V', 'Jin', 'Suga', 'Jungkook']
bts = bts + ['RM'] # µ¡¼À ¿¬ÀÚÀÚ·Î ¸â¹ö 'RM'À» Ãß°¡ÇÔ
bts
list(range(5)) # 0¿¡¼ 5»çÀÌÀÇ Á¤¼ö¿À» »ý¼º(5´Â Æ÷ÇԾȵÊ)
list(range(0, 5)) # list(range(5))¿Í µ¿ÀÏÇÑ °á°ú
list(range(0, 5, 1)) # list(range(0, 5))¿Í µ¿ÀÏÇÑ °á°ú
list(range(0, 5, 2)) # »ý¼ºÇÏ´Â °ªÀ» 2¾¿ Áõ°¡½ÃÅ´
list(range(2, 5)) # 2¿¡¼ 5-1±îÁöÀÇ ¿¬¼ÓµÈ ¼ö 2, 3, 4À» »ý¼º
7.3 ¸®½ºÆ® ¿¬»êÀ» Çغ¸ÀÚ
bts = ['V', 'J-Hope'] + ['RM', 'Jungkook', 'Jin']
bts
numbers = [10, 20, 30] + [40, 50, 60]
numbers
mystery = [0, 1, 2] * 3 # [0, 1, 2]°¡ 3ȸ ¹Ýº¹µÇ¾î ÀúÀåµÊ
mystery
bts = ['V', 'J-Hope', 'RM', 'Jungkook', 'Jin', 'Jimin', 'Suga']
'V' in bts
'V' not in bts
ÀÔ·ÂÀ» ¹Þ¾Æ ¸ÀÀÖ´Â °úÀÏÀÇ ¸®½ºÆ®¸¦ ¸¸µé¾î º¸ÀÚ
fruits = []
name = input('ÁÁ¾ÆÇÏ´Â °úÀÏÀÇ À̸§À» ÀÔ·ÂÇϽÿÀ: ')
fruits.append(name)
name = input('ÁÁ¾ÆÇÏ´Â °úÀÏÀÇ À̸§À» ÀÔ·ÂÇϽÿÀ: ')
fruits.append(name)
name = input('ÁÁ¾ÆÇÏ´Â °úÀÏÀÇ À̸§À» ÀÔ·ÂÇϽÿÀ: ')
fruits.append(name)
name = input('°úÀÏÀÇ À̸§À» ÀÔ·ÂÇϼ¼¿ä: ')
if name in fruits:
print('ÀÌ °úÀÏÀº ´ç½ÅÀÌ ÁÁ¾ÆÇÏ´Â °úÀÏÀÔ´Ï´Ù.')
else:
print('ÀÌ °úÀÏÀº ´ç½ÅÀÌ ÁÁ¾ÆÇÏ´Â °úÀÏÀÌ ¾Æ´Õ´Ï´Ù.')
slist1 = ['Kim', 178.9, 'Park', 173.5, 'Lee', 176.1]
slist1
slist1[0], slist1[2], slist1[4]
slist2 = [ ['Kim', 178.9], ['Park', 173.5], ['Lee', 176.1] ]
slist2
type(slist1)
type(slist2)
n_list = [200, 700, 500, 300, 400]
len(n_list)
max(n_list)
min(n_list)
sum(n_list)
sum(n_list) / len(n_list) # ÀüüÀÇ ÇÕÀ» ¿ø¼ÒÀÇ °³¼ö·Î ³ª´©¸é Æò±Õ°ªÀ» ¾òÀ» ¼ö ÀÖ´Ù
list(range(1,11))
a_list = [0, '']
any(n_list)
any(a_list)
# Àα¸ Åë°è(´ÜÀ§: õ¸í)
Seoul = 9765
Busan = 3441
Incheon = 2954
city_pop = [ Seoul, Busan, Incheon ] # º¯¼öµé·Î ¸®½ºÆ® »ý¼º
print(city_pop) # ¸®½ºÆ® µ¥ÀÌÅ͸¦ Ãâ·Â
# <¹®Á¦¿¡¼ Á¦½ÃµÈ Äڵ带 ¿©±â¿¡ »ðÀÔÇÑ´Ù>
Daejeon = 1531
city_pop.append(Daejeon)
max_pop = 0
min_pop = 1000000
pop_sum = 0
n = 0
for pop in city_pop: # ¼øȯ¹®À» µ¹¸é¼ ÃÖ´ñ°ª, ÃÖ¼Ú°ªÀ» ±¸ÇÑ´Ù
if pop > max_pop :
max_pop = pop
if pop < min_pop :
min_pop = pop
pop_sum += pop
n += 1
print('ÃÖ´ë Àα¸:', max_pop)
print('ÃÖ¼Ò Àα¸:', min_pop)
print('Æò±Õ Àα¸:', pop_sum / n)
letters = ['A', 'B', 'C', 'D', 'E', 'F']
letters[0] # ¸®½ºÆ®ÀÇ Ã¹ Ç׸ñ¿¡ Á¢±Ù
letters[1]
letters[2]
letters[-1]
bts = ['V', 'RM', 'Jungkook', 'J-Hop', 'Suga', 'Jin', 'Jimin']
len(bts) # ¸®½ºÆ®ÀÇ ¿ø¼Ò °³¼ö¸¦ ¾ò´Â´Ù
bts[len(bts)-1] # ¸¶Áö¸· ¿ø¼Ò
bts[-1] # À½¼ö À妽º·Î ¸¶Áö¸· ¿ø¼Ò¸¦ ½±°Ô Á¢±ÙÇÒ ¼ö ÀÖ´Ù
min(bts) # ¸®½ºÆ® ¿ø¼Ò Áß °¡Àå ÀÛÀº °ªÀ» ã´Â´Ù. (¹®ÀÚ¿Àº »çÀü½Ä ¼ø¼)
max(bts) # ¸®½ºÆ® ¿ø¼Ò Áß °¡Àå Å« °ªÀ» ã´Â´Ù. (¹®ÀÚ¿Àº »çÀü½Ä ¼ø¼)
letters = ['A', 'B', 'C', 'D', 'E', 'F']
letters[0]
letters[1]
letters[2]
letters[-1]
alist = ['a', 'aa', 'ff', 'f', 'b', 'c']
len(alist) # ¸®½ºÆ®ÀÇ ¿ø¼Ò °³¼ö¸¦ ¾ò´Â´Ù
alist[len(alist)-1] # ¸¶Áö¸· ¿ø¼Ò
alist[len(alist)-1] # ¸¶Áö¸· ¿ø¼Ò
min(alist) # ¸®½ºÆ® ¿ø¼Ò Áß °¡Àå ÀÛÀº °ªÀ» ã´Â´Ù. (¹®ÀÚ¿Àº »çÀü½Ä ¼ø¼)
max(alist) # ¸®½ºÆ® ¿ø¼Ò Áß °¡Àå Å« °ªÀ» ã´Â´Ù. (¹®ÀÚ¿Àº »çÀü½Ä ¼ø¼)
letters = ['A', 'B', 'C', 'D', 'E', 'F']
letters[2:5]
letters[:3]
letters[3:]
letters[:]
letters[::2]
letters[::-1] # µÚ¿¡¼ºÎÅÍ ¾ÕÀ¸·Î Àоî¿À¸ç ¿ø¼Ò¸¦ »ý¼ºÇÑ´Ù
µµ½ÃÀÇ Àα¸ ÀÚ·á¿¡ ´ëÇÑ ½½¶óÀ̽ÌÀ» Çغ¸ÀÚ
# ´ÙÀ½°ú °°Àº ¸®½ºÆ®°¡ »ý¼ºµÇ¾î ÀÖ´Ù.
population = ["Seoul", 9765, "Busan", 3441, "Incheon", 2954]
print('¼¿ï Àα¸:', population[1]) # ¹®Á¦ 1)
print('ÀÎõ Àα¸:', population[-1]) # ¹®Á¦ 2)
cities = population[0::2] # ¹®Á¦ 3)
print('µµ½Ã ¸®½ºÆ®:', cities)
pops = population[1::2] # ¹®Á¦ 4)
print('Àα¸ÀÇ ÇÕ:', sum(pops))
slist = ['Kim', 178.9, 'Park', 173.5, 'Lee', 176.1]
slist[3] = 175.0
slist
slist[2:4] = ['Paik', 180.0]
slist
slist.insert(4, "Hong")
slist.insert(5, 168.1)
slist
bts = [ "V", "J-Hope", "Suga", "Jungkook" ]
bts.remove("Jungkook")
bts
bts = ["V", "J-Hope", "Suga", "Jungkook"]
last_member = bts.pop() # ¸¶Áö¸· Ç׸ñ 'Jungkook'À» »èÁ¦ÇÏ°í ¹ÝȯÇÑ´Ù
last_member
bts
bts = [ "V", "J-Hope", "Suga", "Jungkook"]
del bts[0] # ¸®½ºÆ®ÀÇ Ã¹ Ç׸ñÀ» »èÁ¦ÇÏ´Â ¸í·É¾î
bts
alist = ['Kim', 'Park', 'Lee', 'Hong']
blist = alist
blist[1] = 'Choi' # blistÀÇ µÎ¹ø° Ç׸ñ°ªÀ» º¯°æÇÔ
alist
id(alist)
id(blist) # À§ÀÇ °ª°ú µ¿ÀÏÇÔ
alist = ['Kim', 'Park', 'Lee', 'Hong']
blist = list(alist)
id(alist)
id(blist) # blistÀÇ ¾ÆÀ̵ð´Â alistÀÇ ¾ÆÀ̵ð¿Í ´Ù¸¦ °ÍÀÌ´Ù.
blist = alist[:] # ÀÌ·¸°Ô ÇÏ¿©µµ µÈ´Ù.
id(alist)
id(blist) # blistÀÇ ¾ÆÀ̵ð´Â alistÀÇ ¾ÆÀ̵ð¿Í ´Ù¸¦ °ÍÀÌ´Ù.
blist[0] = 'Song'
alist # alistÀÇ º¹»çº» blist¸¦ °íÃÆÀ¸¹Ç·Î ¾Æ¹«·± º¯È°¡ ¾ø´Ù
blist # alistÀÇ º¹»çº»ÀÇ Ã¹ ¹ø° Ç׸ñÀÌ º¯°æµÊ
bts = [ "V", "J-Hope", "Suga", "Jungkook" ]
bts.index("Suga")
if "Suga" in bts:
print(bts.index("Suga"))
bts = ["V", "J-Hope", "Suga", "Jungkook" ]
for member in bts:
print(member)
numbers = [ 9, 6, 7, 1, 8, 4, 5, 3, 2 ]
numbers.sort()
print(numbers)
numbers.sort(reverse=True)
print(numbers)
bts = [ "V", "J-Hope", "Suga", "Jungkook" ]
bts.sort()
print(bts)
numbers = [ 9, 6, 7, 1, 8, 4, 5, 3, 2 ]
new_list = sorted(numbers)
print(new_list)
print(numbers)
numbers = [ 9, 6, 7, 1, 8, 4, 5, 3, 2 ]
new_list = sorted(numbers, reverse=True)
print(new_list)
sorted("FADEAWAY")
import random
quotes = []
quotes.append("²ÞÀ» Áö³à¶ó. ±×·¯¸é ¾î·Á¿î Çö½ÇÀ» ÀÌ±æ ¼ö ÀÖ´Ù.")
quotes.append("ºÐ³ë´Â ¹Ùº¸µéÀÇ °¡½¿¼Ó¿¡¼¸¸ »ì¾Æ°£´Ù..")
quotes.append("°í»ý ¾øÀÌ ¾òÀ» ¼ö ÀÖ´Â Áø½Ç·Î ±ÍÁßÇÑ °ÍÀº Çϳªµµ ¾ø´Ù.")
quotes.append("»ç¶÷Àº »ç¶ûÇÒ ¶§ ´©±¸³ª ½ÃÀÎÀÌ µÈ´Ù.")
quotes.append("½ÃÀÛÀÌ ¹ÝÀÌ´Ù.")
print("############################")
print("# ¿À´ÃÀÇ ¸í¾ð #")
print("############################")
print("")
dailyQuote = random.choice(quotes)
print(dailyQuote)
eval("100 + 200") # ¹®ÀÚ¿À» ÆÄÀ̽㠹®ÀåÀ¸·Î Çؼ®ÇÏ¿© 100 + 200À» ¼öÇàÇÔ
[ x**2 for x in [1, 2, 3, 4, 5] ]
s = []
for x in [1, 2, 3, 4, 5]:
s.append(x**2)
[x for x in range(10)]# 0¿¡¼ 9±îÁö ¼ýÀÚ¸¦ Æ÷ÇÔÇÏ´Â ¸®½ºÆ®
[x * x for x in range(10)] # 0¿¡¼ 9±îÁö ¼ýÀÚÀÇ Á¦°ö °ª
st = 'Hello World'
[x.upper() for x in st] # ¹®ÀÚ¿ °¢°¢¿¡ ´ëÇØ upper() ¸Þ¼Òµå Àû¿ë
a = ['welcome', 'to', 'the', 'python', 'world']
first_a = [ s[0].upper() for s in a] # ù ¾ËÆĺª¿¡ ´ëÇÑ ´ë¹®ÀÚ º¯È¯
print(first_a)
[x for x in range(10) if x % 2 == 0]
[x**2 for x in range(10) if x % 2 == 0] # Ãâ·Â½Ä¿¡ Á¦°öÀ» ÇÒ ¼ö ÀÖ´Ù
s = ["Hello", "12345", "World", "67890"]
numbers = [x for x in s if x.isdigit()]
print(numbers)
[int(x) for x in input('Á¤¼ö¸¦ ¿©·¯°³ ÀÔ·ÂÇϼ¼¿ä : ').split()]
[int(x) for x in input('Á¤¼ö¸¦ ¿©·¯°³ ÀÔ·ÂÇϼ¼¿ä : ').split() if x.isdigit()]
[(x, y) for x in [1, 2, 3] for y in [3, 1, 4]]
[(x, y) for x in [1, 2, 3] for y in [3, 1, 4] if x != y]
colors = ("red", "green", "blue")
colors
numbers = (1, 2, 3, 4, 5 )
numbers
t1 = (1, 2, 3, 4, 5)
t1[0] = 100
t1 = (1, 2, 3, 4, 5)
t1[0] # Æ©ÇÃÀÇ À妽Ì-¸®½ºÆ® Àε¦½Ì°ú µ¿ÀÏÇÑ ¹æ½Ä
t1[1:4] # Æ©ÇÃÀÇ ½½¶óÀÌ½Ì °á°ú·Î Æ©ÇÃÀ» ¹ÝȯÇÔ
t2 = t1 + t1 # Æ©ÇÃÀÇ °áÇÕ ¿¬»ê
t2
LAB7-5 ÇÔ¼ö´Â Æ©ÇÃÀ» µ¹·ÁÁÙ ¼ö ÀÖ´Ù
import math
def calCircle(r):
# ¹ÝÁö¸§ÀÌ rÀÎ ¿øÀÇ ³ÐÀÌ¿Í µÑ·¹¸¦ µ¿½Ã¿¡ ¹ÝȯÇÏ´Â ÇÔ¼ö (area, circum)
area = math.pi * r * r
circum = 2 * math.pi * r
return area, circum # Æ©ÇÃÀ» ¹ÝȯÇÔ
radius = float(input("¿øÀÇ ¹ÝÁö¸§À» ÀÔ·ÂÇϽÿÀ: "))
(a, c) = calCircle(radius)
print("¿øÀÇ ³ÐÀÌ´Â "+str(a)+"ÀÌ°í ¿øÀÇ µÑ·¹´Â"+str(c)+"ÀÌ´Ù.")
city_info = [('¼¿ï', 9765), ('ºÎ»ê', 3441), ('ÀÎõ', 2954),
('±¤ÁÖ', 1501), ('´ëÀü', 1531)]
max_pop = 0
min_pop = 999999999999999999
total_pop = 0
max_city = None
min_city = None
for city in city_info:
total_pop += city[1]
if city[1] > max_pop :
max_pop = city[1]
max_city = city
if city[1] < min_pop :
min_pop = city[1]
min_city = city
print('ÃÖ´ëÀα¸: {0}, Àα¸: {1} õ¸í'.format(max_city[0], max_city[1]))
print('ÃÖ¼ÒÀα¸: {0}, Àα¸: {1} õ¸í'.format(min_city[0], min_city[1]))
print('¸®½ºÆ® µµ½Ã Æò±Õ Àα¸: {0} õ¸í'.format(total_pop / len(city_info)) )
animals = ['lion', 'tiger', 'cat', 'dog']
animals.sort() # animals ¸®½ºÆ®ÀÇ ³»ºÎ ¹®ÀÚ¿À» ¾ËÆĺª ¼øÀ¸·Î Á¤·ÄÇÑ´Ù
animals
animals.append('rabbit') # animals ¸®½ºÆ®¿¡ »õ ¿ø¼Ò¸¦ Ãß°¡ÇÑ´Ù
animals
animals.reverse() # animals ¸®½ºÆ®¸¦ ¿ø·¡ ¿ø¼ÒÀÇ ¿ª¼øÀ¸·Î Àç¹è¿ÇÑ´Ù
animals