์ „์ฒด ๊ธ€ 102

211027_Code in the morning

Q1 ์ฃผ์–ด์ง„ ์ž์—ฐ์ˆ˜๊ฐ€ ํ™€์ˆ˜์ธ์ง€ ์ง์ˆ˜์ธ์ง€ ํŒ๋ณ„ํ•ด ์ฃผ๋Š” ํ•จ์ˆ˜(is_odd)๋ฅผ ์ž‘์„ฑํ•ด ๋ณด์ž. ํ’€์ด: ๋”๋ณด๊ธฐ def is_odd(num): if num % 2 == 1: return True else : return False Q2 ์ž…๋ ฅ์œผ๋กœ ๋“ค์–ด์˜ค๋Š” ๋ชจ๋“  ์ˆ˜์˜ ํ‰๊ท  ๊ฐ’์„ ๊ณ„์‚ฐํ•ด ์ฃผ๋Š” ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด ๋ณด์ž. (๋‹จ ์ž…๋ ฅ์œผ๋กœ ๋“ค์–ด์˜ค๋Š” ์ˆ˜์˜ ๊ฐœ์ˆ˜๋Š” ์ •ํ•ด์ ธ ์žˆ์ง€ ์•Š๋‹ค.) โ€ป ํ‰๊ท  ๊ฐ’์„ ๊ตฌํ•  ๋•Œ len ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด ๋ณด์ž. ํ’€์ด: ๋”๋ณด๊ธฐ def avg_num(*args) : result = 0 for i in args: result += i result = result/len(args) return result Q3 ๋‹ค์Œ์€ ๋‘ ๊ฐœ์˜ ์ˆซ์ž๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ ๋”ํ•˜์—ฌ ๋Œ๋ ค์ฃผ๋Š” ํ”„๋กœ๊ทธ๋žจ์ด๋‹ค. input1 = input("์ฒซ๋ฒˆ์งธ ์ˆซ์ž๋ฅผ ์ž…..

211026_Code in the morning

Q5 A ํ•™๊ธ‰์— ์ด 10๋ช…์˜ ํ•™์ƒ์ด ์žˆ๋‹ค. ์ด ํ•™์ƒ๋“ค์˜ ์ค‘๊ฐ„๊ณ ์‚ฌ ์ ์ˆ˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. [70, 60, 55, 75, 95, 90, 80, 80, 85, 100] for๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ A ํ•™๊ธ‰์˜ ํ‰๊ท  ์ ์ˆ˜๋ฅผ ๊ตฌํ•ด ๋ณด์ž. ํ’€์ด: ๋”๋ณด๊ธฐ A A = [70, 60, 55, 75, 95, 90, 80, 80, 85, 100] total = 0 for score in A: total += score average = total / len(A) print(average) Q6 ๋ฆฌ์ŠคํŠธ ์ค‘์—์„œ ํ™€์ˆ˜์—๋งŒ 2๋ฅผ ๊ณฑํ•˜์—ฌ ์ €์žฅํ•˜๋Š” ๋‹ค์Œ ์ฝ”๋“œ๊ฐ€ ์žˆ๋‹ค. numbers = [1, 2, 3, 4, 5] result = [] for n in numbers: if n % 2 == 1: result.append(n*2) ์œ„ ์ฝ”๋“œ๋ฅผ ๋ฆฌ์ŠคํŠธ ๋‚ด..

[python] ์ž…์ถœ๋ ฅ(ํ‘œ์ค€์ž…์ถœ๋ ฅ, ๋‹ค์–‘ํ•œ ์ถœ๋ ฅํฌ๋งท, ํŒŒ์ผ์ž…์ถœ๋ ฅ, pickle, with)

ํ‘œ์ค€ ์ž…์ถœ๋ ฅ #sep, end print("python","java", sep=" vs ") #sep๊ฐ’์„ ์„ค์ •ํ•ด์„œ ๊ฐ , ์‚ฌ์ด์— ๋„ฃ์„ ์ˆ˜ ์žˆ์Œ print("python","java", sep=" , " , end = "?") #end์˜ ์˜๋ฏธ๋Š” ๋ฌธ์žฅ์˜ ๋งˆ์ง€๋ง‰์„ ?๋กœ ํ•ด๋‹ฌ๋ผ. #์ขŒ์šฐ์ •๋ ฌ(rjust(), ljust()) scores = {"์ˆ˜ํ•™":0, "์˜์–ด":50, "์ฝ”๋”ฉ":100} for subject, score in scores.items(): print(subject, score) print(subject.ljust(8), str(score).rjust(4), sep=":") #๊ณผ๋ชฉ ์™ผ์ชฝ์œผ๋กœ ์ •๋ ฌํ•˜๋Š”๋ฐ, 8์นธ ๋‚จ๊ธฐ๊ณ  ์ •๋ ฌํ•ด๋‹ฌ๋ผ / score ๋ถ€๋ถ„์€ ์˜ค๋ฅธ์ชฝ ์ •๋ ฌํ•˜๋Š”๋ฐ 4์นธ ๊ณต๊ฐ„ ํ™•๋ณด #1์„ 001๋กœ ๋งŒ..

Coding/Python 2021.10.24

211024_Code in the Morning

Q1 ๋‹ค์Œ ์ฝ”๋“œ์˜ ๊ฒฐ๊ณผ๊ฐ’์€ ๋ฌด์—‡์ผ๊นŒ? a = "Life is too short, you need python" if "wife" in a: print("wife") elif "python" in a and "you" not in a: print("python") elif "shirt" not in a: print("shirt") elif "need" in a: print("need") else: print("none") A: shirt Q2 while๋ฌธ์„ ์‚ฌ์šฉํ•ด 1๋ถ€ํ„ฐ 1000๊นŒ์ง€์˜ ์ž์—ฐ์ˆ˜ ์ค‘ 3์˜ ๋ฐฐ์ˆ˜์˜ ํ•ฉ์„ ๊ตฌํ•ด ๋ณด์ž. A: result = 0 i = 1 while i 5 : break print("*" * i) Q4 for๋ฌธ์„ ์‚ฌ์šฉํ•ด 1๋ถ€ํ„ฐ 100๊นŒ์ง€์˜ ์ˆซ์ž๋ฅผ ์ถœ๋ ฅํ•ด ๋ณด์ž. A: for i in r..

211023_Code in the Morning

https://wikidocs.net/42526 02์žฅ ์—ฐ์Šต๋ฌธ์ œ *(์—ฐ์Šต๋ฌธ์ œ ํ’€์ด : [https://wikidocs.net/12769#02](https://wikidocs.net/12769#02))* ## Q1 ํ™๊ธธ๋™ ์”จ์˜ ๊ณผ๋ชฉ๋ณ„ ... wikidocs.net Q1 ํ™๊ธธ๋™ ์”จ์˜ ๊ณผ๋ชฉ๋ณ„ ์ ์ˆ˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. ํ™๊ธธ๋™ ์”จ์˜ ํ‰๊ท  ์ ์ˆ˜๋ฅผ ๊ตฌํ•ด ๋ณด์ž. ๊ณผ๋ชฉ์ ์ˆ˜ ๊ตญ์–ด 80 ์˜์–ด 75 ์ˆ˜ํ•™ 55 Q2 ์ž์—ฐ์ˆ˜ 13์ด ํ™€์ˆ˜์ธ์ง€ ์ง์ˆ˜์ธ์ง€ ํŒ๋ณ„ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ๋งํ•ด ๋ณด์ž. Q3 ํ™๊ธธ๋™ ์”จ์˜ ์ฃผ๋ฏผ๋“ฑ๋ก๋ฒˆํ˜ธ๋Š” 881120-1068234์ด๋‹ค. ํ™๊ธธ๋™ ์”จ์˜ ์ฃผ๋ฏผ๋“ฑ๋ก๋ฒˆํ˜ธ๋ฅผ ์—ฐ์›”์ผ(YYYYMMDD) ๋ถ€๋ถ„๊ณผ ๊ทธ ๋’ค์˜ ์ˆซ์ž ๋ถ€๋ถ„์œผ๋กœ ๋‚˜๋ˆ„์–ด ์ถœ๋ ฅํ•ด ๋ณด์ž. โ€ป ๋ฌธ์ž์—ด ์Šฌ๋ผ์ด์‹ฑ ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•ด ๋ณด์ž. Q4 ์ฃผ๋ฏผ๋“ฑ๋ก๋ฒˆํ˜ธ ๋’ท์ž๋ฆฌ์˜ ๋งจ ์ฒซ ๋ฒˆ..

[python] ํ•จ์ˆ˜(ํ•จ์ˆ˜, ์ „๋‹ฌ๊ฐ’๊ณผ ๋ฐ˜ํ™˜๊ฐ’, ํ‚ค์›Œ๋“œ๊ฐ’, ๊ธฐ๋ณธ๊ฐ’, ๊ฐ€๋ณ€์ธ์ž, ์ง€์—ญ๋ณ€์ˆ˜์™€ ์ „์—ญ๋ณ€์ˆ˜)

ํ•จ์ˆ˜ def deposit(balance, money): print("์ž…๊ธˆ์ด ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ž”์•ก์€ {0}์›์ž…๋‹ˆ๋‹ค".format(balance+money)) return balance + money ์ „๋‹ฌ๊ฐ’๊ณผ ๋ฐ˜ํ™˜๊ฐ’ def deposit(balance, money): print("์ž…๊ธˆ์ด ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ž”์•ก์€ {0}์›์ž…๋‹ˆ๋‹ค".format(balance+money)) return balance + money # ํ•จ์ˆ˜ ๋‚ด์—์„œ ์–ด๋–ค ๋™์ž‘์„ ํ•˜๊ณ  ๋‚˜์„œ ํŠน์ • '๊ฐ’'์„ ๋ฐ˜ํ™˜ํ•ด์ค„ ๋•Œ return ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. # ๊ทธ๋Ÿฌ๋ฉด ๊ทธ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๊ณณ์—์„œ ๋ฐ˜ํ™˜๋ฐ›์€ return ๊ฐ’์„ ๋ณ€์ˆ˜์— ๋‹ด์•„์„œ ์ดํ›„์— ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. def withdraw(balance, money): #์ถœ๊ธˆ if balance > money: #์ž”์•ก์ด..

Coding/Python 2021.10.21

[python] ์ œ์–ด๋ฌธ(if, for, while, continue, break)

if weather = input("์˜ค๋Š˜ ๋‚ ์”จ๋Š” ์–ด๋•Œ์š”?") #์‚ฌ์šฉ์ž ์ธํ’‹์„ ํ•„์š”๋กœ ํ•จ if weather == "๋น„" or weather == "๋ˆˆ": print("์šฐ์‚ฐ์„ ์ฑ™๊ธฐ์„ธ์š”") elif weather == "๋ฏธ์„ธ๋จผ์ง€": print("๋งˆ์Šคํฌ๋ฅผ ์ฑ™๊ธฐ์„ธ์š”.") else: print("์ค€๋น„๋ฌผ ํ•„์š”์—†์–ด์š”.") for for waiting_no in range(1,6): #1, 2, 3, 4, 5 print("๋Œ€๊ธฐ๋ฒˆํ˜ธ : {0}".format(waiting_no)) #์Šคํƒ€๋ฒ…์Šค ์†๋‹˜ starbucks = ["์•„์ด์–ธ๋งจ", "ํ† ๋ฅด", "์•„์ด์— ๊ทธ๋ฃจํŠธ"] for cumstomer in starbucks: print("{0}๋‹˜, ์ปคํ”ผ๊ฐ€ ์ค€๋น„๋˜์—ˆ์Šต๋‹ˆ๋‹ค.".format(customer)) while #5๋ฒˆ์ด๋‚˜ ๋ถˆ๋ €๋Š”๋ฐ ..

Coding/Python 2021.10.20

[python] ์ž๋ฃŒ๊ตฌ์กฐ(๋ฆฌ์ŠคํŠธ, ์‚ฌ์ „, ํŠœํ”Œ, ์„ธํŠธ)

๋ฆฌ์ŠคํŠธ subway1 = 10 subway2 = 20 subway3 = 30 ์ด๊ฑฐ๋ฅผ subway = [10, 20, 30] ์œผ๋กœ ์“ธ ์ˆ˜ ์žˆ๋‹ค. ex) subway = ["์œ ์žฌ์„", "์กฐ์„ธํ˜ธ", "๋ฐ•๋ช…์ˆ˜"] #์กฐ์„ธํ˜ธ์”จ๊ฐ€ ๋ช‡ ๋ฒˆ์งธ์— ํƒ€๊ณ  ์žˆ๋Š”๊ฐ€? subway.index("์กฐ์„ธํ˜ธ") #ํ•˜ํ•˜๊ฐ€ ๋‹ค์Œ ์ •๋ฅ˜์žฅ์—์„œ ๋‹ค์Œ ์นธ์— ํƒ‘์Šน subway.append("ํ•˜ํ•˜") #์ •ํ˜•๋ˆ์„ ์œ ์žฌ์„/์กฐ์„ธํ˜ธ ์‚ฌ์ด์— ํƒœ์›€ subway.insert(1,"์ •ํ˜•๋ˆ") #์ง€ํ•˜์ฒ ์— ์žˆ๋Š” ์‚ฌ๋žŒ๋“ค์ด ๋’ค์—์„œ ํ•œ ๋ช…์”ฉ ํ•˜์ฐจ subway.pop() #๊ฐ™์€ ์ด๋ฆ„์˜ ์‚ฌ๋žŒ์ด ๋ช‡ ๋ช… ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ subway.count("์œ ์žฌ์„") #์ •๋ ฌ num_list = [1, 2, 3, 4, 5] num_list.sort() #์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ num_list.revers..

Coding/Python 2021.10.20

[python] ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ(๋ฌธ์ž์—ด, ์Šฌ๋ผ์ด์‹ฑ, ํ•จ์ˆ˜, ํฌ๋งท, ํƒˆ์ถœ๋ฌธ์ž)

๋ฌธ์ž์—ด sentence = '๋‚˜๋Š” ์†Œ๋…„์ž…๋‹ˆ๋‹ค.' sentence2 = "ํŒŒ์ด์ฌ์€ ์‰ฌ์›Œ์š”" sentence3 = """๋‚˜๋Š” ์†Œ๋…„์ด๊ณ , ํŒŒ์ด์ฌ์€ ์‰ฌ์›Œ์š”""" ์Šฌ๋ผ์ด์‹ฑ ์Šฌ๋ผ์ด์‹ฑ: ํ•„์š”ํ•œ๋งŒํผ ์ž˜๋ผ์„œ ์“ฐ๋Š” ๊ฒƒ ex) ์ฃผ๋ฏผ๋ฒˆํ˜ธ jumin = "980129-1234567" ์„ฑ๋ณ„ : jumin[7] ์—ฐ๋„ : jumin[0:2] #0๋ถ€ํ„ฐ 2 ์ง์ „๊นŒ์ง€(0,1) ์›” : jumin[2:4] ์ผ : jumin[4:6] ์ƒ๋…„์›”์ผ : jumin[:6] #์ฒ˜์Œ๋ถ€ํ„ฐ 6 ์ง์ „๊นŒ์ง€ ๋’ค 7์ž๋ฆฌ : jumin[7:] #7๋ถ€ํ„ฐ ๋๊นŒ์ง€ ๋’ค 7์ž๋ฆฌ(๋’ค๋ถ€ํ„ฐ) jumin[-7:] #๋งจ ๋’ค์—์„œ 7๋ฒˆ์งธ๋ถ€ํ„ฐ ๋๊นŒ์ง€ (๋งจ ๋’ค๋Š” -1) ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌํ•จ์ˆ˜ ex) python = "Python is Amazing." ์†Œ๋ฌธ์ž python.lower() ๋Œ€๋ฌธ์ž pyt..

Coding/Python 2021.10.18

[python] ์—ฐ์‚ฐ์ž(์—ฐ์‚ฐ์ž, ๊ฐ„๋‹จํ•œ ์ˆ˜์‹, ์ˆซ์ž์ฒ˜๋ฆฌํ•จ์ˆ˜, ๋žœ๋ค)

์—ฐ์‚ฐ์ž ** : ์ œ๊ณฑ % : ๋‚˜๋จธ์ง€ // : ๋ชซ >= == : ๊ฐ™๋‹ค != : ๊ฐ™์ง€ ์•Š๋‹ค print(not(1!=3)) : True & : and | : or ์ˆซ์ž ์ฒ˜๋ฆฌ ํ•จ์ˆ˜ abs() : ์ ˆ๋Œ€๊ฐ’ pow(4,2) : 4^2 max min round: ๋ฐ˜์˜ฌ๋ฆผ from math import * #math๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ๋ชจ๋“  ๊ฒƒ์„ ์ด์šฉ floor: ๋‚ด๋ฆผ ceiling: ์˜ฌ๋ฆผ sqrt: ์ œ๊ณฑ๊ทธ๋Š ๋žœ๋คํ•จ์ˆ˜ from random import * random() : 0.0 ์ด์ƒ 1.0 ๋ฏธ๋งŒ์˜ ์ž„์˜๊ฐ’์„ ์ƒ์„ฑ random() * 10 : 0.0 ์ด์ƒ 10.0 ๋ฏธ๋งŒ์˜ ์ž„์˜์˜ ๊ฐ’์„ ์ƒ์„ฑ int(random() * 10) : 0๋ถ€ํ„ฐ 10 ๋ฏธ๋งŒ์˜ ์ž„์˜์˜ ์ •์ˆ˜๊ฐ’ ์ƒ์„ฑ int(random() * 10) + 1 : 1๋ถ€ํ„ฐ 10์ดํ•˜์˜ ์ž„์˜..

Coding/Python 2021.10.18