๐Ÿ”ฅํŒŒ์ด์ฌ ์ค‘๊ธ‰ ๋ฌธ์ œ

Jane์˜ study note.ยท2022๋…„ 10์›” 1์ผ
0

ํŒŒ์ด์ฌ Python

๋ชฉ๋ก ๋ณด๊ธฐ
25/31
post-thumbnail

1. ํŒŒ์ด์ฌ ์ค‘๊ธ‰(์ด๋ก ) ๋ฌธ์ œ ๋ชฉ์ฐจ

1.ํ•จ์ˆ˜

01_ํ•จ์ˆ˜๋ž€
๊ณ„์‚ฐ๊ธฐ ๋งŒ๋“ค๊ธฐ

02_ํ•จ์ˆ˜ ์„ ์–ธ๊ณผ ํ˜ธ์ถœ
๏ƒ˜ ์˜ค๋Š˜ ๋‚ ์”จ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  3๋ฒˆ ํ˜ธ์ถœํ•ด๋ณด์ž.
๏ƒ˜ ์ •์ˆ˜ ๋‘ ๊ฐœ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๊ณฑ์…ˆ๊ณผ ๋‚˜๋ˆ—์…ˆ ์—ฐ์‚ฐ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค๊ณ  ํ˜ธ์ถœํ•ด๋ณด์ž.

03_ํ•จ์ˆ˜ ๋‚ด์—์„œ ๋˜ ๋‹ค๋ฅธ ํ•จ์ˆ˜ ํ˜ธ์ถœ
๏ƒ˜ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ตฌ๊ตฌ๋‹จ ์ถœ๋ ฅ ํ•จ์ˆ˜๊ฐ€ ์—ฐ์‡„์ ์œผ๋กœ ํ˜ธ์ถœ๋˜๋„๋ก ํ•จ์ˆ˜๋ฅผ ์„ ์–ธํ•ด๋ณด์ž.

04_์ธ์ˆ˜์™€ ๋งค๊ฐœ๋ณ€์ˆ˜
๏ƒ˜ ๊ตญ์–ด, ์˜์–ด, ์ˆ˜ํ•™ ์ ์ˆ˜๋ฅผ ์ž…๋ ฅ๋ฐ›๊ณ , ์ž…๋ ฅ๋ฐ›์€ ์ ์ˆ˜๋ฅผ ์ด์šฉํ•ด์„œ ์ด์ ๊ณผ ํ‰๊ท ์„ ์ถœ๋ ฅํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด ๋ณด์ž.

05_๋ฐ์ดํ„ฐ ๋ฐ˜ํ™˜
๏ƒ˜ ์‚ฌ์šฉ์ž๊ฐ€ ๊ธธ์ด(cm)๋ฅผ ์ž…๋ ฅํ•˜๋ฉด mm๋กœ ํ™˜์‚ฐํ•œ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž.

06_์ง€์—ญ๋ณ€์ˆ˜์™€ ์ ผ์—ญ๋ณ€์ˆ˜
๏ƒ˜ ์‚ฌ์šฉ์ž๊ฐ€ ๊ฐ€๋กœ, ์„ธ๋กœ ๊ธธ์ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์‚ผ๊ฐํ˜•๊ณผ ์‚ฌ๊ฐํ˜•์˜ ๋„“์ด๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž.
๏ƒ˜ ๋ฐฉ๋ฌธ๊ฐ ์ˆ˜๋ฅผ ์นด์šดํŠธํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž.

07_์ค‘์ฒฉํ•จ์ˆ˜
๏ƒ˜ calculator()ํ•จ์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  calculator() ์•ˆ์— ๋ง์…ˆ, ๋บ„์…ˆ, ๊ณฑ์…ˆ, ๋‚˜๋ˆ—์…ˆ ํ•จ์ˆ˜๋ฅผ ์„ ์–ธํ•˜์ž.

08_lambda ํ•จ์ˆ˜
๏ƒ˜ ์‚ผ๊ฐํ˜•, ์‚ฌ๊ฐํ˜•, ์›์˜ ๋„“์ด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” lambdaํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž.

2. ๋ชจ๋“ˆ

09_๋ชจ๋“ˆ
๏ƒ˜ ramdom ๋ชจ๋“ˆ์„ ์ด์šฉํ•ด์„œ 1๋ถ€ํ„ฐ 10๊นŒ์ง€์˜ ์ •์ˆ˜ ์ค‘ ๋‚œ์ˆ˜ 1๊ฐœ๋ฅผ ๋ฐœ์ƒ์‹œ์ผœ ๋ณด์ž.
๏ƒ˜ ramdom ๋ชจ๋“ˆ์„ ์ด์šฉํ•ด์„œ 0๋ถ€ํ„ฐ 100์‚ฌ์ด์˜ ๋‚œ์ˆ˜ 10๊ฐœ๋ฅผ ๋ฐœ์ƒ์‹œ์ผœ ๋ณด์ž.

10_๋ชจ๋“ˆ์ œ์ž‘
๏ƒ˜ ๋กœ๋˜ ๋ฒˆํ˜ธ(6๊ฐœ)๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ๋ชจ๋“ˆ์„ ๋งŒ๋“ค์–ด ๋ณด์ž.
๏ƒ˜ ๋ฌธ์ž์—ด์„ ๊ฑฐ๊พธ๋กœ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ชจ๋“ˆ์„ ๋งŒ๋“ค์–ด๋ณด์ž.

11_๋ชจ๋“ˆ์‚ฌ์šฉ
๏ƒ˜ ๊ตญ์–ด, ์˜์–ด, ์ˆ˜ํ•™ ์ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์ด์ , ํ‰๊ท ์„ ์ถœ๋ ฅํ•˜๋Š” ๋ชจ๋“ˆ์„ ๋งŒ๋“ค์–ด๋ณด์ž.

12_์‹คํ–‰(๋ฉ”์ธ) ํŒŒ์ผ (01)

13_์‹คํ–‰(๋ฉ”์ธ) ํŒŒ์ผ (02)
๏ƒ˜ ๋‹จ์œ„ ํ™˜์‚ฐ ๋ชจ๋“ˆ์„ ๋งŒ๋“ค๊ณ  cm๋ฅผ mm, inch, m, ft๋กœ ๋ณ€ํ™˜ํ•ด๋ณด์ž.

14_ํŒจํ‚ค์ง€

15_site-packages
๏ƒ˜ site-packages์— ์•ฝ์ˆ˜์™€ ์†Œ์ˆ˜๋ฅผ ๋ฆฌ์ŠคํŠธ๋กœ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ชจ๋“ˆ์„ ๋งŒ๋“ค์–ด๋ณด์ž.

16_์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ์™ธ๋ถ€ ๋ชจ๋“ˆ

3. ํด๋ž˜์Šค

17_๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ
๊ณ„์‚ฐ๊ธฐ ํด๋ž˜์Šค ๋งŒ๋“ค๊ธฐ
์ž๋™์ฐจ ํด๋ž˜์Šค ๋งŒ๋“ค๊ธฐ

18_ํด๋ž˜์Šค์™€ ๊ฐ์ฒด ์ƒ์„ฑ
๏ƒ˜ ๋น„ํ–‰๊ธฐ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ๋น„ํ–‰๊ธฐ ๊ฐ์ฒด 5๊ฐœ๋ฅผ ์ƒ์„ฑํ•ด ๋ณด์ž.

19_๊ฐ์ฒด ์†์„ฑ ๋ณ€๊ฒฝ
์†์„ฑ ๋ณ€๊ฒฝ์„ ํ†ตํ•œ PC์—…๊ทธ๋ ˆ์ด๋“œ ํ•ด๋ณด๊ธฐ
๏ƒ˜ ๊ณ„์‚ฐ๊ธฐ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ์‚ฌ์น™์—ฐ์‚ฐ์„ ์‹คํ–‰ํ•ด ๋ณด์ž.

20_๊ฐ์ฒด์™€ ๋ฉ”๋ชจ๋ฆฌ
๏ƒ˜ ๊ตญ์–ด, ์˜์–ด, ์ˆ˜ํ•™ ์ ์ˆ˜๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ ๋ฆฌ์ŠคํŠธ์— ์ €์žฅํ•˜๊ณ  ์›๋ณธ์„ ์œ ์ง€ํ•œ ์ƒํƒœ๋กœ, ๋ณต์‚ฌ๋ณธ์„ ๋งŒ๋“ค์–ด ๊ณผ๋ชฉ๋ณ„ ์ ์ˆ˜๋ฅผ 10% ์˜ฌ๋ ธ์„ ๊ฒฝ์šฐ์— ํ‰๊ท ์„ ์ถœ๋ ฅํ•ด ๋ณด์ž.

21_์–•์€๋ณต์‚ฌ์™€ ๊นŠ์€๋ณต์‚ฌ
๏ƒ˜ ์„ ์ˆ˜์˜ ์›๋ณธ ์ ์ˆ˜๋ฅผ ์ด์šฉํ•ด์„œ ํ‰๊ท ์„ ์ถœ๋ ฅํ•˜๊ณ , ์ตœ๊ณ ๊ฐ’๊ณผ ์ตœ์ €๊ฐ’์„ ์ œ์™ธํ•œ ํ‰๊ท ์„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค์–ด๋ณด์ž.

22_ํด๋ž˜์Šค ์ƒ์†
๏ƒ˜ ๋ง์…ˆ, ๋บ„์…ˆ ๊ธฐ๋Šฅ์ด ์žˆ๋Š” ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ณ , ์ด๋ฅผ ์ƒ์†ํ•˜๋Š” ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด์„œ ๊ณฑ์…ˆ๊ณผ ๋‚˜๋ˆ”์…ˆ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•ด ๋ณด์ž.

23_์ƒ์„ฑ์ž (01)

24_์ƒ์„ฑ์ž (02)
๏ƒ˜ ์ค‘๊ฐ„๊ณ ์‚ฌ ํด๋ž˜์Šค์™€ ๊ธฐ๋ง๊ณ ์‚ฌ ํด๋ž˜์Šค๋ฅผ ์ƒ์†๊ด€๊ณ„๋กœ ๋งŒ๋“ค๊ณ  ๊ฐ๊ฐ์˜ ์ ์ˆ˜๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜์ž. ๋˜ํ•œ ์ด์  ๋ฐ ํ‰๊ท ์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ๊ธฐ๋Šฅ๋„ ๋งŒ๋“ค์–ด๋ณด์ž.

25_๋‹ค์ค‘ ์ƒ์†
๏ƒ˜ BasicCalculator์™€ DeveloperCalculator ํด๋ž˜์Šค๋ฅผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋งŒ๋“ค๊ณ  ์ด๋“ค ํด๋ž˜์Šค๋ฅผ ์ƒ์†ํ•ด์„œ Calculator ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ์‚ฌ์šฉํ•ด ๋ณด์ž.

26_์˜ค๋ฒ„๋ผ์ด๋”ฉ

  • ๋กœ๋ด‡ ํด๋ž˜์Šค ์ƒ์†๋ฐ›์•„ ๋‰ด๋กœ๋ด‡ ํด๋ž˜์Šค ๋งŒ๋“ค๊ธฐ
    ๏ƒ˜ ์‚ผ๊ฐํ˜• ๋„“์ด๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ์ด๋ฅผ ์ƒ์†ํ•˜๋Š” ํด๋ž˜์Šค์—์„œ getArea()๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋”ฉ ํ•ด์„œ ์ถœ๋ ฅ ๊ฒฐ๊ณผ๊ฐ€ ๋‹ค์Œ๊ณผ ๊ฐ™์„ ์ˆ˜ ์žˆ๋„๋ก ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž.

27_์ถ”์ƒํด๋ž˜์Šค
๏ƒ˜ ๊ณ„์‚ฐ๊ธฐ ์ถ”์ƒ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ์ด๋ฅผ ์ด์šฉํ•ด์„œ ์ƒˆ๋กœ์šด ๊ณ„์‚ฐ๊ธฐ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด ๋ณด์ž. ์ถ”์ƒ ํด๋ž˜์Šค์—๋Š” ๋ง์…ˆ, ๋บ„์…ˆ, ๊ณฑ์…ˆ, ๋‚˜๋ˆ—์…ˆ ๊ธฐ๋Šฅ์ด ์„ ์–ธ๋˜์–ด ์žˆ์–ด์•ผ ํ•œ๋‹ค.

4. ์˜ˆ์™ธ์ฒ˜๋ฆฌ

28_์˜ˆ์™ธ๋ž€

29_์˜ˆ์™ธ์ฒ˜๋ฆฌ
๏ƒ˜ ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ˆซ์ž 5๊ฐœ๋ฅผ ์ž…๋ ฅ๋ฐ›์„ ๋•Œ ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ์ž๋ฃŒํ˜•์ด ์ž…๋ ฅ๋˜๋ฉด ์˜ˆ์™ธ ์ฒ˜๋ฆฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค์–ด๋ณด์ž.

30_try ~ except ~ else
๏ƒ˜ ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ˆซ์ž 5๊ฐœ๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ ์ง์ˆ˜, ํ™€์ˆ˜, ์‹ค์ˆ˜๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ๊ฐ๊ฐ์„ ๋ฆฌ์ŠคํŠธ์— ์ €์žฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค์–ด๋ณด์ž.

31_finally
๏ƒ˜ ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ˆซ์ž 5๊ฐœ๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ ์ง์ˆ˜, ํ™€์ˆ˜, ์‹ค์ˆ˜์™€ ์ž…๋ ฅํ•œ ๋ชจ๋“  ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ๊ฐ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค์–ด๋ณด์ž.

32_Exception ํด๋ž˜์Šค
๏ƒ˜ raise ํ‚ค์›Œ๋“œ๋ฅผ ์ด์šฉํ•˜๋ฉด ์˜ˆ์™ธ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค.
๏ƒ˜ ์‚ฌ์šฉ์ž๊ฐ€ ๋ฌธ์ž ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ผ๋•Œ 10๊ธ€์ž ์ดํ•˜๋ฉด SMS๋กœ ๋ฐœ์†กํ•˜๊ณ , 10๊ธ€์ž๋ฅผ ์ดˆ๊ณผํ•˜๋ฉด MMS๋กœ ๋ฐœ์†กํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋ฅผ ์ด์šฉํ•ด์„œ ๋งŒ๋“ค์–ด๋ณด์ž.

33_์‚ฌ์šฉ์ž Exception ํด๋ž˜์Šค
๏ƒ˜ ๊ด€๋ฆฌ์ž ์•”ํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ๋‹ค์Œ ์ƒํƒœ์— ๋”ฐ๋ผ ์˜ˆ์™ธ ์ฒ˜๋ฆฌํ•˜๋Š” ์˜ˆ์™ธ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž.
โ€ข ์•”ํ˜ธ ๊ธธ์ด๊ฐ€ 5๋ฏธ๋งŒ์ธ ๊ฒฝ์šฐ: PasswordLengthShortException
โ€ข ์•”ํ˜ธ ๊ธธ์ด๊ฐ€ 10์„ ์ดˆ๊ณผํ•˜๋Š” ๊ฒฝ์šฐ: PasswordLengthLongException
โ€ข ์•”ํ˜ธ๊ฐ€ ์ž˜๋ชป๋œ ๊ฒฝ์šฐ: PasswordWrongException

5. ํ…์ŠคํŠธํŒŒ์ผ

34_ํ…์ŠคํŠธ ํŒŒ์ผ ์“ฐ๊ธฐ
๏ƒ˜ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‹œ์Šคํ…œ ์‹œ๊ฐ„๊ณผ ์ผ์ •์„ ํ…์ŠคํŠธ ํŒŒ์ผ์— ์ž‘์„ฑํ•ด ๋ณด์ž.

35_ํ…์ŠคํŠธ ํŒŒ์ผ ์ฝ๊ธฐ
๏ƒ˜ ๋‹ค์Œ ํ…์ŠคํŠธ ํŒŒ์ผ์—์„œ โ€˜Pythonโ€™์„ โ€˜ํŒŒ์ด์ฌโ€™์œผ๋กœ ๋ณ€๊ฒฝํ•ด์„œ ํŒŒ์ผ์— ๋‹ค์‹œ ์ €์žฅํ•ด๋ณด์ž.

36_ํ…์ŠคํŠธ ํŒŒ์ผ ์—ด๊ธฐ
๏ƒ˜ ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ์ˆซ์ž์— ๋Œ€ํ•œ ์†Œ์ˆ˜๋ฅผ ๊ตฌํ•˜๊ณ  ์ด๋ฅผ ํŒŒ์ผ์— ์ž‘์„ฑํ•ด๋ณด์ž.

37_with ~ as๋ฌธ
๏ƒ˜ ๋กœ๋˜ ๋ฒˆํ˜ธ ์ƒ์„ฑ๊ธฐ ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค๊ณ  ํŒŒ์ผ์— ๋ฒˆํ˜ธ๋ฅผ ์ถœ๋ ฅํ•ด ๋ณด์ž.

38_writelines()
๏ƒ˜ ๋”•์…”๋„ˆ๋ฆฌ์— ์ €์žฅ๋œ ๊ณผ๋ชฉ๋ณ„ ์ ์ˆ˜๋ฅผ ํŒŒ์ผ์— ์ €์žฅํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์ž.

39_readlines(), readline()
๏ƒ˜ ํŒŒ์ผ์— ์ €์žฅ๋œ ๊ณผ๋ชฉ๋ณ„ ์ ์ˆ˜๋ฅผ ํŒŒ์ด์ฌ์—์„œ ์ฝ์–ด, ๋”•์…”๋„ˆ๋ฆฌ์— ์ €์žฅํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž.


2. ํŒŒ์ด์ฌ ์ค‘๊ธ‰ ์—ฐ์Šต๋ฌธ์ œ ๋ฆฌ์ŠคํŠธ

1.ํ•จ์ˆ˜

01 ์‚ฐ์ˆ  ์—ฐ์‚ฐ ๊ณ„์‚ฐ๊ธฐ๋ฅผ ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ
02 ์ด๋™๊ฑฐ๋ฆฌ, ์ด๋™์‹œ๊ฐ„ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ
03 ๋น„ํ–‰๊ธฐ ํ‹ฐ์ผ“ ์˜์ˆ˜์ฆ ์ถœ๋ ฅ ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ
04 ์žฌ๊ท€ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด ํŒฉํ† ๋ฆฌ์–ผ ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ + ๋‹จ๋ฆฌ/์›”๋ณต๋ฆฌ ๊ณ„์‚ฐ๊ธฐ ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ
05 ๋“ฑ์ฐจ์ˆ˜์—ด์˜ n๋ฒˆ์งธ ๊ฐ’๊ณผ ํ•ฉ์„ ์ถœ๋ ฅํ•˜๋Š” ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ
06 ๋“ฑ๋น„์ˆ˜์—ด์˜ n๋ฒˆ์งธ ๊ฐ’๊ณผ ํ•ฉ์„ ์ถœ๋ ฅํ•˜๋Š” ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ

2. ๋ชจ๋“ˆ

01 ๊ณผ๋ชฉ๋ณ„ ์ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•ด ํ•ฉ๊ฒฉ ์—ฌ๋ถ€๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ๋ชจ๋“ˆ ๋งŒ๋“ค๊ธฐ
02 ์ƒํ’ˆ ๊ตฌ๋งค ๊ฐœ์ˆ˜์— ๋”ฐ๋ผ ํ• ์ธ์œจ์ด ๊ฒฐ์ •๋˜๋Š” ๋ชจ๋“ˆ ๋งŒ๋“ค๊ธฐ
03 ๋กœ๋˜ ๋ชจ๋“ˆ ๋งŒ๋“ค์–ด ๋กœ๋˜ ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋  ์ˆ˜ ์žˆ๋Š” ํ”„๋กœ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ
04 ์ˆœ์—ด ๊ณ„์‚ฐ ๋ชจ๋“ˆ ๋งŒ๋“ค๊ธฐ
05 ์กฐํ•ฉ ๊ณ„์‚ฐ ๋ชจ๋“ˆ ๋งŒ๋“ค๊ธฐ
06 ์ˆ˜์ž…๊ณผ ๊ณต๊ณผ๊ธˆ์„ ์ž…๋ ฅํ•ด ๊ณต๊ณผ๊ธˆ ์ด์•ก๊ณผ ์ˆ˜์ž… ๋Œ€๋น„ ๊ณต๊ณผ๊ธˆ ๋น„์œจ์„ ๊ณ„์‚ฐํ•˜๋Š” ๋ชจ๋“ˆ ๋งŒ๋“ค๊ธฐ
07 ํŒจํ‚ค์ง€์™€ ๋ชจ๋“ˆ์„ ๋งŒ๋“ค์–ด ์—ฐ์‚ฐ๊ฒฐ๊ณผ ์ถœ๋ ฅํ•˜๊ธฐ

3. ํด๋ž˜์Šค

01 ํšŒ์›๊ฐ€์ž… ํด๋ž˜์Šค์™€ ํšŒ์›์ •๋ณด๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ํšŒ์›๊ฐ€์ž… ๋กœ๊ทธ์ธ ๊ตฌํ˜„ํ•˜๊ธฐ
02 TVํด๋ž˜์Šค๋ฅผ ์ƒ์†Œ๊ตฌ์กฐ๋กœ ๋งŒ๋“ค์–ด ๊ฐ์ฒด ์ƒ์„ฑํ•˜๊ธฐ
03 ๋ช…์„ธ์„œ๋ฅผ ์ฐธ๊ณ ํ•ด ๋„์„œ ๊ด€๋ฆฌ ํ”„๋กœ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ
04 ํ•œ์˜, ํ•œ์ผ ์‚ฌ์ „ ํด๋ž˜์Šค ๋งŒ๋“ค๊ธฐ (# ์ถ”์ƒํด๋ž˜์Šค #@)
05 ์ฃผ์‚ฌ์œ„ ๊ฒŒ์ž„ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ์ปดํ“จํ„ฐ์™€ ์‚ฌ์šฉ์ž์˜ ๊ฒŒ์ž„ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜๊ธฐ
06 ์ž๋™์ฐจ ๊ฒฝ์ฃผ ๊ฒŒ์ž„ ํด๋ž˜์Šค ๋งŒ๋“ค๊ธฐ
07 mp3 ํ”Œ๋ ˆ์ด์–ด ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ๋…ธ๋ž˜ ๋“ฑ๋ก ํ›„ ์žฌ์ƒํ•˜๊ธฐ

4. ์˜ˆ์™ธ์ฒ˜๋ฆฌ

01 ์‚ฐ์ˆ ์—ฐ์‚ฐ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜๊ณ  ์˜ˆ์ƒ๋˜๋Š” ์˜ˆ์™ธ์ฒ˜๋ฆฌ ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ
02 1๋ถ€ํ„ฐ 1000๊นŒ์ง€์˜ ์†Œ์ˆ˜์ธ ๋‚œ์ˆ˜๋ฅผ 10๊ฐœ ์ƒ์„ฑํ•˜๋˜ ์†Œ๊ตฌ๊ฐ€ ์•„๋‹ˆ๋ฉด ์‚ฌ์šฉ์ž ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•˜๋„๋ก ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ
03 ์ด๊ตฌ๋งค๊ธˆ์•ก์„ ์ถœ๋ ฅํ•˜๋˜ ๊ฐœ์ˆ˜๊ฐ€ ์ž˜๋ชป ์ž…๋ ฅ๋œ ๊ฒฝ์šฐ ๋ณ„๋„๋กœ ์ถœ๋ ฅํ•˜๋„๋ก ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ
04 ํšŒ์› ๊ฐ€์ž… ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค๋˜ ์ž…๋ ฅํ•˜์ง€ ์•Š์€ ํ•ญ๋ชฉ์ด ์žˆ๋Š” ๊ฒฝ์šฐ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ
05 ์€ํ–‰ ๊ณ„์ขŒ ๊ฐœ์„ค ๋ฐ ์ž…/์ถœ๊ธˆ ํ”„๋กœ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ

5. ํ…์ŠคํŠธํŒŒ์ผ

01 ํšŒ์› ๊ณ„์ •๋ณ„ ํ…์ŠคํŠธ ํŒŒ์ผ์„ ์ƒ์„ฑํ•œ ํ›„ ํšŒ์› ๋ณธ์ธ ํŒŒ์ผ์— ํ•œ์ค„ ์ผ๊ธฐ๋ฅผ ์“ฐ๊ณ  ์ฝ๋Š” ํ”„๋กœ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ
02 ์ˆ˜์ž…๊ณผ ์ง€์ถœ์„ ๊ธฐ๋กํ•˜๋Š” ๊ฐ€๊ณ„๋ถ€ ๋งŒ๋“ค๊ธฐ
03 ์ˆซ์ž์˜ ์•ฝ์ˆ˜์™€ ์†Œ์ˆ˜๋ฅผ ํ…์ŠคํŠธ ํŒŒ์ผ์— ๊ธฐ๋กํ•˜๊ธฐ
04 ๋‘๊ฐœ์˜ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๊ณต์•ฝ์ˆ˜, ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜๋ฅผ ํ…์ŠคํŠธ ํŒŒ์ผ์— ์ž‘์„ฑํ•˜๊ธฐ
05 ๋ฐฐ(๊ณผ์ผ)๊ฐ€ ์ž…ํ•ญํ•˜๋Š” ๋‚ ์งœ๋ฅผ ํ…์ŠคํŠธ ํŒŒ์ผ์— ๊ธฐ๋กํ•ด๋ณด๊ธฐ

3. ํŒŒ์ด์ฌ ์ค‘๊ธ‰ ์—ฐ์Šต๋ฌธ์ œ

๋งํฌ:ํŒŒ์ด์ฌ ์ค‘๊ธ‰ ์—ฐ์Šต๋ฌธ์ œํ’€์ด

1.ํ•จ์ˆ˜(01~06)

01 ์‚ฐ์ˆ  ์—ฐ์‚ฐ ๊ณ„์‚ฐ๊ธฐ๋ฅผ ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ

def add(n1, n2):
    return n1 + n2

def sub(n1, n2):
    return n1 - n2

def mul(n1, n2):
    return n1 * n2

def div(n1, n2):
    return n1 / n2

def mod(n1, n2):
    return n1 % n2

def flo(n1, n2):
    return n1 // n2

def exp(n1, n2):
    return n1 ** n2

while True:

    print('-' * 60)
    selectNum = int(input('1.๋ง์…ˆ, 2.๋บ„์…ˆ, 3.๊ณฑ์…ˆ, 4.๋‚˜๋ˆ—์…ˆ, 5.๋‚˜๋จธ์ง€, 6.๋ชซ, 7.์ œ๊ณฑ์Šน, 8.์ข…๋ฃŒ '))
    if selectNum == 8:
        print('Bye~')
        break

    num1 = float(input('์ฒซ ๋ฒˆ์งธ ์ˆซ์ž ์ž…๋ ฅ: '))
    num2 = float(input('๋‘ ๋ฒˆ์งธ ์ˆซ์ž ์ž…๋ ฅ: '))

    if selectNum == 1:
        print(f'{num1} + {num2} = {add(num1, num2)}')

    elif selectNum == 2:
        print(f'{num1} - {num2} = {sub(num1, num2)}')

    elif selectNum == 3:
        print(f'{num1} * {num2} = {mul(num1, num2)}')

    elif selectNum == 4:
        print(f'{num1} / {num2} = {div(num1, num2)}')

    elif selectNum == 5:
        print(f'{num1} % {num2} = {mod(num1, num2)}')

    elif selectNum == 6:
        print(f'{num1} // {num2} = {flo(num1, num2)}')

    elif selectNum == 7:
        print(f'{num1} ** {num2} = {exp(num1, num2)}')

    else:
        print('์ž˜๋ชป ์ž…๋ ฅํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•˜์„ธ์š”.')

    print('-' * 60)

02 ์ด๋™๊ฑฐ๋ฆฌ, ์ด๋™์‹œ๊ฐ„ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ (๋ฌธ2)

# ๊ฑฐ๋ฆฌ(km) = ์†๋„(km/h) * ์‹œ๊ฐ„(h)
def getDistance(speed, hour, minute):
    distance = speed * (hour + (minute / 60))

    return distance


def getTime(speed, distance):

    # 100 : 75 = 60 : x  -->  x = 75 * 60 / 100
    time = distance / speed
    print(f'time: {time}')
    h = int(time)
    m = int((time - h) * 100 * 60 / 100)
    # m = convertFloatToMinute(time - h)

    return [h, m]


def convertFloatToMinute(f):
    return int(f * 100 * 60 / 100)


print('-' * 60)
s = float(input('์†๋„(km/h) ์ž…๋ ฅ: '))
h = float(input('์‹œ๊ฐ„(h) ์ž…๋ ฅ: '))
m = float(input('์‹œ๊ฐ„(m) ์ž…๋ ฅ: '))
d = getDistance(s, h, m)
print(f'{s}(km/h)์†๋„๋กœ {h}(h)์‹œ๊ฐ„ {m}(m)๋ถ„ ๋™์•ˆ ์ด๋™ํ•œ ๊ฑฐ๋ฆฌ: {d}(km)')
print('-' * 60)



print('-' * 60)
s = float(input('์†๋„(km/h) ์ž…๋ ฅ: '))
d = float(input('๊ฑฐ๋ฆฌ(km) ์ž…๋ ฅ: '))
t = getTime(s, d)
print(f'{s}(km/h) ์†๋„๋กœ {d}(km) ์ด๋™ํ•œ ์‹œ๊ฐ„: {t[0]}(h)์‹œ๊ฐ„ {t[1]}(m)๋ถ„')
print('-' * 60)

03 ๋น„ํ–‰๊ธฐ ํ‹ฐ์ผ“ ์˜์ˆ˜์ฆ ์ถœ๋ ฅ ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ

childPrice = 18000
infantPrice = 25000
adultPrice = 50000
specialDC = 50

def formatedNumber(n):
    return format(n, ',')

def printAriPlaneReceipt(c1, c2, i1, i2, a1, a2):

    print('=' * 40)
    cp = c1 * childPrice
    cp_dc = int(c2 * childPrice * 0.5)
    print(f'์œ ์•„ {c1}๋ช… ์š”๊ธˆ: {formatedNumber(cp)}์›')
    print(f'์œ ์•„ ํ• ์ธ ๋Œ€์ƒ {c2}๋ช… ์š”๊ธˆ: {formatedNumber(cp_dc)}์›')

    ip = i1 * infantPrice
    ip_dc = int(i2 * infantPrice * 0.5)
    print(f'์†Œ์•„ {i1}๋ช… ์š”๊ธˆ: {formatedNumber(ip)}์›')
    print(f'์†Œ์•„ ํ• ์ธ ๋Œ€์ƒ {i2}๋ช… ์š”๊ธˆ: {formatedNumber(ip_dc)}์›')

    ap = a1 * adultPrice
    ap_dc = int(a2 * adultPrice * 0.5)
    print(f'์„ฑ์ธ {a1}๋ช… ์š”๊ธˆ: {formatedNumber(ap)}์›')
    print(f'์„ฑ์ธ ํ• ์ธ ๋Œ€์ƒ {a2}๋ช… ์š”๊ธˆ: {formatedNumber(ap_dc)}์›')

    print('=' * 40)
    print(f'Total: {formatedNumber(c1 + c2 + i1 + i2 + a1 + a2)}๋ช…')
    print(f'TotalPrice : {formatedNumber(cp + cp_dc + ip + ip_dc + ap + ap_dc)}์›')
    print('=' * 40)


print(f'childPrice(24๊ฐœ์›” ๋ฏธ๋งŒ)\t\t: {formatedNumber(childPrice)}์›')
print(f'infantPrice(๋งŒ12์„ธ ๋ฏธ๋งŒ)\t\t: {formatedNumber(infantPrice)}์›')
print(f'adultPrice(๋งŒ12์„ธ ์ดํ›„)\t\t: {formatedNumber(adultPrice)}์›')
print(f'๊ตญ๊ฐ€ ์œ ๊ณต์ž ๋ฐ ์žฅ์• ์šฐ ํ• ์ธ\t\t: {specialDC}%')
print()

childCnt = int(input('์œ ์•„ ์ž…๋ ฅ: '))
specialDCChildCnt = int(input(f'ํ• ์ธ๋Œ€์ƒ ์œ ์•„ ์ž…๋ ฅ: '))

infantCnt = int(input('์†Œ์•„ ์ž…๋ ฅ: '))
specialDCInfantCnt = int(input(f'ํ• ์ธ๋Œ€์ƒ ์†Œ์•„ ์ž…๋ ฅ: '))

adultCnt = int(input('์„ฑ์ธ ์ž…๋ ฅ: '))
specialDCAdultCnt = int(input(f'ํ• ์ธ๋Œ€์ƒ ์„ฑ์ธ ์ž…๋ ฅ: '))


printAriPlaneReceipt(childCnt, specialDCChildCnt,
                infantCnt, specialDCInfantCnt,
                adultCnt, specialDCAdultCnt)

04 ์žฌ๊ท€ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด ํŒฉํ† ๋ฆฌ์–ผ ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ + ๋‹จ๋ฆฌ/์›”๋ณต๋ฆฌ ๊ณ„์‚ฐ๊ธฐ ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ

def formatedNumber(n):
    return format(n, ',')


def recursionFun(n):

    if n == 1:
        return n
    return n * recursionFun(n - 1)

inputNumber = int(input('input number: '))
inputNumberFormated = formatedNumber(recursionFun(inputNumber))
print(inputNumberFormated)


# ๋‹จ๋ฆฌ ๊ณ„์‚ฐ๊ธฐ
def singleRateCalculator(m, t, r):
    totalMoney = 0
    totalRateMoney = 0

    for i in range(t):
        totalRateMoney += m * (r * 0.01)

    totalMoney = m + totalRateMoney
    return int(totalMoney)


# ์›”๋ณต๋ฆฌ ๊ณ„์‚ฐ๊ธฐ
def multiRateCalculator(m, t, r):

    t = t * 12
    rpm = (r / 12) * 0.01
    totalMoney = m

    for i in range(t):
        totalMoney += totalMoney * rpm

    return int(totalMoney)



money = int(input('์˜ˆ์น˜๊ธˆ(์›): '))
term = int(input('๊ธฐ๊ฐ„(๋…„): '))
rate = int(input('์—ฐ ์ด์œจ(%): '))

print()
print('[๋‹จ๋ฆฌ ๊ณ„์‚ฐ๊ธฐ]')
print('=' * 30)
print(f'์˜ˆ์น˜๊ธˆ\t: {formatedNumber(money)}์›')
print(f'์˜ˆ์น˜๊ธฐ๊ฐ„\t: {term}๋…„')
print(f'์—ฐ ์ด์œจ\t: {rate}%')
print('-' * 30)
amount = formatedNumber(singleRateCalculator(money, term, rate))
print(f'{term}๋…„ ํ›„ ์ด ์ˆ˜๋ น์•ก: {amount}์›')
print('=' * 30)


print()
print('[์›”๋ณต๋ฆฌ ๊ณ„์‚ฐ๊ธฐ]')
print('=' * 30)
print(f'์˜ˆ์น˜๊ธˆ\t: {formatedNumber(money)}์›')
print(f'์˜ˆ์น˜๊ธฐ๊ฐ„\t: {term}๋…„')
print(f'์—ฐ ์ด์œจ\t: {rate}%')
print('-' * 30)
amount = formatedNumber(multiRateCalculator(money, term, rate))
print(f'{term}๋…„ ํ›„ ์ด ์ˆ˜๋ น์•ก: {amount}์›')
print('=' * 30)

05 ๋“ฑ์ฐจ์ˆ˜์—ด์˜ n๋ฒˆ์งธ ๊ฐ’๊ณผ ํ•ฉ์„ ์ถœ๋ ฅํ•˜๋Š” ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ

def sequenceCal(n1, d, n):

    valueN = 0
    sumN = 0
    i = 1
    while i <= n:

        if i == 1:
            valueN = n1
            sumN += valueN
            print('{}๋ฒˆ์งธ ํ•ญ์˜ ๊ฐ’: {}'.format(i, valueN))
            print('{}๋ฒˆ์งธ ํ•ญ๊นŒ์ง€์˜ ํ•ฉ: {}'.format(i, sumN))
            i += 1
            continue

        valueN += d
        sumN += valueN
        print('{}๋ฒˆ์งธ ํ•ญ์˜ ๊ฐ’: {}'.format(i, valueN))
        print('{}๋ฒˆ์งธ ํ•ญ๊นŒ์ง€์˜ ํ•ฉ: {}'.format(i, sumN))
        i += 1


def sequenceCal01(n1, d, n):

    # ๋“ฑ์ฐจ ์ˆ˜์—ด(์ผ๋ฐ˜ํ•ญ) ๊ณต์‹: an = a1 + (n-1) * d
    valueN = n1 + (n-1) * d
    print('{}๋ฒˆ์งธ ํ•ญ์˜ ๊ฐ’: {}'.format(n, valueN))

    # ๋“ฑ์ฐจ ์ˆ˜์—ด(ํ•ฉ) ๊ณต์‹: sn = n(a1 + an) / 2
    sumN = n * (n1 + valueN) / 2
    print('{}๋ฒˆ์งธ ํ•ญ๊นŒ์ง€์˜ ํ•ฉ: {}'.format(n, int(sumN)))


inputN1 = int(input('a1 ์ž…๋ ฅ: '))
inputD = int(input('๊ณต์ฐจ ์ž…๋ ฅ: '))
inputN = int(input('n ์ž…๋ ฅ: '))

sequenceCal(inputN1, inputD, inputN)
print('-' * 50)
sequenceCal01(inputN1, inputD, inputN)

06 ๋“ฑ๋น„์ˆ˜์—ด์˜ n๋ฒˆ์งธ ๊ฐ’๊ณผ ํ•ฉ์„ ์ถœ๋ ฅํ•˜๋Š” ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ

def sequenceCal(n1, r, n):

    valueN = 0
    sumN = 0
    i = 1

    while i <= inputN:

        if i == 1:
            valueN = n1
            sumN += valueN
            print('{}๋ฒˆ์งธ ํ•ญ์˜ ๊ฐ’: {}'.format(i, valueN))
            print('{}๋ฒˆ์งธ ํ•ญ๊นŒ์ง€์˜ ํ•ฉ: {}'.format(i, sumN))
            i += 1
            continue

        valueN *= r
        sumN += valueN
        print('{}๋ฒˆ์งธ ํ•ญ์˜ ๊ฐ’: {}'.format(i, valueN))
        print('{}๋ฒˆ์งธ ํ•ญ๊นŒ์ง€์˜ ํ•ฉ: {}'.format(i, sumN))
        i += 1



def sequenceCal01(n1, r, n):

    # ๋“ฑ๋น„ ์ˆ˜์—ด(์ผ๋ฐ˜ํ•ญ) ๊ณต์‹: an = a1 * r^(n-1)
    valueN = n1 * (r ** (n - 1))
    print('{}๋ฒˆ์งธ ํ•ญ์˜ ๊ฐ’: {}'.format(n, valueN))

    # ๋“ฑ๋น„ ์ˆ˜์—ด(ํ•ฉ) ๊ณต์‹: sn = a1 * (1 - r^n) / (1-r)
    sumN = n1 * (1 - (r ** n)) / (1 - r)
    print('{}๋ฒˆ์งธ ํ•ญ๊นŒ์ง€์˜ ํ•ฉ: {}'.format(n, int(sumN)))



inputN1 = int(input('a1 ์ž…๋ ฅ: '))
inputR = int(input('๊ณต๋น„ ์ž…๋ ฅ: '))
inputN = int(input('n ์ž…๋ ฅ: '))


sequenceCal(inputN1, inputR, inputN)
print('-' * 50)
sequenceCal01(inputN1, inputR, inputN)

2. ๋ชจ๋“ˆ(01~07)

01 ๊ณผ๋ชฉ๋ณ„ ์ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•ด ํ•ฉ๊ฒฉ ์—ฌ๋ถ€๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ๋ชจ๋“ˆ ๋งŒ๋“ค๊ธฐ

# passOrFail.py
def exampleResult(s1, s2, s3, s4, s5):

    passAvgScore = 60
    limitScore = 40

    def getTotal():
        totalScore = s1 + s2 + s3 + s4 + s5
        print(f'์ด์ : {totalScore}')
        return totalScore

    def getAverage():
        avg = getTotal() / 5
        print(f'ํ‰๊ท : {avg}')
        return avg

    def printPassOrFail():
        print(f'{s1}: Pass') if s1 >= limitScore else print(f'{s1}: Fail')
        print(f'{s2}: Pass') if s2 >= limitScore else print(f'{s2}: Fail')
        print(f'{s3}: Pass') if s3 >= limitScore else print(f'{s3}: Fail')
        print(f'{s4}: Pass') if s4 >= limitScore else print(f'{s4}: Fail')
        print(f'{s5}: Pass') if s5 >= limitScore else print(f'{s5}: Fail')

    def printFinalPassOrFail():

        if getAverage() >= passAvgScore:
            if s1 >= limitScore and s2 >= limitScore and s3 >= limitScore and s4 >= limitScore and s5 >= limitScore:
                print('Final Pass!!')

            else:
                print('Final Fail!!')

        else:
            print('Final Fail!!')


    getAverage()
    printPassOrFail()
    printFinalPassOrFail()



if __name__ == '__main__':
    sub1 = int(input('๊ณผ๋ชฉ1 ์ ์ˆ˜ ์ž…๋ ฅ: '))
    sub2 = int(input('๊ณผ๋ชฉ2 ์ ์ˆ˜ ์ž…๋ ฅ: '))
    sub3 = int(input('๊ณผ๋ชฉ3 ์ ์ˆ˜ ์ž…๋ ฅ: '))
    sub4 = int(input('๊ณผ๋ชฉ4 ์ ์ˆ˜ ์ž…๋ ฅ: '))
    sub5 = int(input('๊ณผ๋ชฉ5 ์ ์ˆ˜ ์ž…๋ ฅ: '))

    exampleResult(sub1, sub2, sub3, sub4, sub5)


def exampleResult(*s):

    passAvgScore = 60
    limitScore = 40

    def getTotal():
        totalScore = sum(s)
        print(f'์ด์ : {totalScore}')
        return totalScore

    def getAverage():
        avg = getTotal() / len(s)
        print(f'ํ‰๊ท : {avg}')
        return avg

    def printPassOrFail():
        for idx, score in enumerate(s):
            print(f'๊ณผ๋ชฉ{idx+1}: Pass') if score >= limitScore else print(f'๊ณผ๋ชฉ{idx+1}: Fail')

    def printFinalPassOrFail():

        result = 'Final Pass!!'

        if getAverage() >= passAvgScore:
            for idx, score in enumerate(s):
                if score < limitScore:
                    result = 'Final Fail!!'
                    break
        else:
            result = 'Final Fail!!'

        print(result)

    getAverage()
    printPassOrFail()
    printFinalPassOrFail()

if __name__ == '__main__':
    sub1 = int(input('๊ณผ๋ชฉ1 ์ ์ˆ˜ ์ž…๋ ฅ: '))
    sub2 = int(input('๊ณผ๋ชฉ2 ์ ์ˆ˜ ์ž…๋ ฅ: '))
    sub3 = int(input('๊ณผ๋ชฉ3 ์ ์ˆ˜ ์ž…๋ ฅ: '))
    sub4 = int(input('๊ณผ๋ชฉ4 ์ ์ˆ˜ ์ž…๋ ฅ: '))
    sub5 = int(input('๊ณผ๋ชฉ5 ์ ์ˆ˜ ์ž…๋ ฅ: '))
    exampleResult(sub1, sub2, sub3, sub4, sub5)

# ex.py
import  passOrFail as pf

if __name__ == '__main__':
    sub1 = int(input('๊ณผ๋ชฉ1 ์ ์ˆ˜ ์ž…๋ ฅ: '))
    sub2 = int(input('๊ณผ๋ชฉ2 ์ ์ˆ˜ ์ž…๋ ฅ: '))
    sub3 = int(input('๊ณผ๋ชฉ3 ์ ์ˆ˜ ์ž…๋ ฅ: '))
    sub4 = int(input('๊ณผ๋ชฉ4 ์ ์ˆ˜ ์ž…๋ ฅ: '))
    sub5 = int(input('๊ณผ๋ชฉ5 ์ ์ˆ˜ ์ž…๋ ฅ: '))

    pf.exampleResult(sub1, sub2, sub3, sub4, sub5)

02 ์ƒํ’ˆ ๊ตฌ๋งค ๊ฐœ์ˆ˜์— ๋”ฐ๋ผ ํ• ์ธ์œจ์ด ๊ฒฐ์ •๋˜๋Š” ๋ชจ๋“ˆ ๋งŒ๋“ค๊ธฐ

# discount.py
def calculatorTotalPrice(gs):

    if len(gs) <= 0:
        print('๊ตฌ๋งค ์ƒํ’ˆ์ด ์—†์Šต๋‹ˆ๋‹ค.')
        return

    rate = 25
    totalPrice = 0

    rates = {1:5, 2:10, 3:15, 4:20}

    if len(gs) in rates:
        rate = rates[len(gs)]

    for g in gs:
        totalPrice += g * (1 - rate * 0.01)

    return [rate, int(totalPrice)]


def formatedNumber(n):
    return format(n, ',')
# ex.py
import  discount as dc

if __name__ == '__main__':
    flag = True
    gs = []

    while flag:
        selectNumber = int(input('์ƒํ’ˆ์„ ๊ตฌ๋งค ํ•˜์‹œ๊ฒ ์–ด์š”? 1.๊ตฌ๋งค 2.์ข…๋ฃŒ '))

        if selectNumber == 1:
            goods_price = int(input('์ƒํ’ˆ ๊ฐ€๊ฒฉ ์ž…๋ ฅ: '))
            gs.append(goods_price)

        elif selectNumber == 2:
            result = dc.calculatorTotalPrice(gs)
            flag = False


    print(f'ํ• ์ธ์œจ: {result[0]}')
    print(f'ํ•ฉ๊ณ„: {dc.formatedNumber(result[1])}์›')

03 ๋กœ๋˜ ๋ชจ๋“ˆ ๋งŒ๋“ค์–ด ๋กœ๋˜ ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋  ์ˆ˜ ์žˆ๋Š” ํ”„๋กœ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ

# lotto.py
import random

userNums = []; randNums = []; collNums = []
randBonuNum = 0

def setUserNums(ns):
    global userNums
    userNums = ns

def getUserNums():
    return userNums

def setRandNums():
    global randNums
    randNums = random.sample(range(1, 46), 6)

def getRandNums():
    return randNums

def setBonuNum():
    global randBonuNum

    while True:
        randBonuNum = random.randint(1, 45)
        if randBonuNum not in randNums:
            break

def getBonuNum():
    return randBonuNum

def lottoResult():
    global userNums
    global randNums
    global collNums

    collNums = []
    for un in userNums:
        if  un in randNums:
            collNums.append(un)

    if len(collNums) == 6:
        print(f'1๋“ฑ ๋‹ด์ฒจ!!')
        print(f'๋ฒˆํ˜ธ: {collNums}')

    elif (len(collNums) == 5) and (randBonuNum in userNums):
        print(f'2๋“ฑ ๋‹ด์ฒจ!!')
        print(f'๋ฒˆํ˜ธ: {collNums}, ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ: {randBonuNum}')

    elif len(collNums) == 5:
        print(f'3๋“ฑ ๋‹ด์ฒจ!!')
        print(f'๋ฒˆํ˜ธ: {collNums}')

    elif len(collNums) == 4:
        print(f'4๋“ฑ ๋‹ด์ฒจ!!')
        print(f'๋ฒˆํ˜ธ: {collNums}')

    if len(collNums) == 3:
        print(f'5๋“ฑ ๋‹ด์ฒจ!!')
        print(f'๋ฒˆํ˜ธ: {collNums}')

    else:
        print('์•„์‰ฝ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ๊ธฐํšŒ์—~')
        print(f'๊ธฐ๊ณ„ ๋ฒˆํ˜ธ: {randNums}')
        print(f'๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ: {randBonuNum}')
        print(f'์„ ํƒ ๋ฒˆํ˜ธ: {userNums}')
        print(f'์ผ์น˜ ๋ฒˆํ˜ธ: {collNums}')


def startLotto():
    n1 = int(input('๋ฒˆํ˜ธ(1~45) ์ž…๋ ฅ: '))
    n2 = int(input('๋ฒˆํ˜ธ(1~45) ์ž…๋ ฅ: '))
    n3 = int(input('๋ฒˆํ˜ธ(1~45) ์ž…๋ ฅ: '))
    n4 = int(input('๋ฒˆํ˜ธ(1~45) ์ž…๋ ฅ: '))
    n5 = int(input('๋ฒˆํ˜ธ(1~45) ์ž…๋ ฅ: '))
    n6 = int(input('๋ฒˆํ˜ธ(1~45) ์ž…๋ ฅ: '))
    selectNums = [n1, n2, n3, n4, n5, n6]

    setUserNums(selectNums)
    setRandNums()
    setBonuNum()

    lottoResult()
# ex.py
import lotto as lt

lt.startLotto()

04 ์ˆœ์—ด ๊ณ„์‚ฐ ๋ชจ๋“ˆ ๋งŒ๋“ค๊ธฐ

# permutation.py
def getPermutaionCnt(n, r, logPrint = True):

    result = 1
    for n in range(n, (n-r), -1):
        if logPrint: print('n : {}'.format(n))
        result = result * n

    return result



from itertools import permutations

def getPermutaions(ns, r):

    pList = list(permutations(ns, r))
    print(f'{len(ns)}P{r} ๊ฐœ์ˆ˜: {len(pList)}')

    for n in permutations(ns, r):
        print(n, end=', ')



if __name__ == '__main__':
    numN = int(input('numN ์ž…๋ ฅ: '))
    numR = int(input('numR ์ž…๋ ฅ: '))


    print(f'{numN}P{numR}: {getPermutaionCnt(numN, numR, logPrint=False)}')

    ns = [1, 2, 3, 4, 5, 6, 7, 8]
    getPermutaions(ns, 3)


# ex.py
import permutation as pt

numN = int(input('numN ์ž…๋ ฅ: '))
numR = int(input('numR ์ž…๋ ฅ: '))

# print(f'{numN}P{numR}: {pt.getPermutaionCnt(numN, numR)}')
print(f'{numN}P{numR}: {pt.getPermutaionCnt(numN, numR, logPrint=False)}')



listVar = [1, 2, 3, 4, 5, 6, 7, 8]
rVar = 3
pt.getPermutaions(listVar, rVar)

05 ์กฐํ•ฉ ๊ณ„์‚ฐ ๋ชจ๋“ˆ ๋งŒ๋“ค๊ธฐ

# combination.py
def getCombinationCnt(n, r, logPrint = True):

    resultP = 1
    resultR = 1
    resultC = 1

    for n in range(n, (n - r), -1):
        resultP = resultP * n
    if logPrint: print('resultP : {}'.format(resultP))


    for n in range(r, 0, -1):
        resultR = resultR * n
    if logPrint: print('resultR: {}'.format(resultR))

    resultC = int(resultP / resultR)
    if logPrint: print('resultC: {}'.format(resultC))

    return resultC



from itertools import combinations

def getCombinations(ns, r):

    cList = list(combinations(ns, r))
    print(f'{len(ns)}C{r} ๊ฐœ์ˆ˜: {len(cList)}')

    for n in combinations(ns, r):
        print(n, end=', ')



if __name__ == '__main__':
    numN = int(input('numN ์ž…๋ ฅ: '))
    numR = int(input('numR ์ž…๋ ฅ: '))


    print(f'{numN}C{numR}: {getCombinationCnt(numN, numR, logPrint=False)}')

    ns = [1, 2, 3, 4, 5, 6, 7, 8]
    getCombinations(ns, 3)



# ex.py
import combination as ct

numN = int(input('numN ์ž…๋ ฅ: '))
numR = int(input('numR ์ž…๋ ฅ: '))

# print(f'{numN}C{numR}: {ct.getCombinationCnt(numN, numR)}')
print(f'{numN}C{numR}: {ct.getCombinationCnt(numN, numR, logPrint=False)}')



listVar = [1, 2, 3, 4, 5, 6, 7, 8]
rVar = 3
ct.getCombinations(listVar, rVar)

06 ์ˆ˜์ž…๊ณผ ๊ณต๊ณผ๊ธˆ์„ ์ž…๋ ฅํ•ด ๊ณต๊ณผ๊ธˆ ์ด์•ก๊ณผ ์ˆ˜์ž… ๋Œ€๋น„ ๊ณต๊ณผ๊ธˆ ๋น„์œจ์„ ๊ณ„์‚ฐํ•˜๋Š” ๋ชจ๋“ˆ ๋งŒ๋“ค๊ธฐ

# utilityBill.py
income = 0
waterPrice = 0; electricPrice = 0; gasPrice = 0

def setIncome(ic):
    global income
    income = ic

def getIncome():
    return income

def setWaterPrice(wp):
    global waterPrice
    waterPrice = wp

def setElectricPrice(ep):
    global electricPrice
    electricPrice = ep

def setGasPrice(gp):
    global gasPrice
    gasPrice = gp

def getUtilityBill():
    result = waterPrice + electricPrice + gasPrice
    return result

def getUtilityBillRate():
    result = getUtilityBill() / getIncome() * 100
    return round(result, 2)

def formatedNumber(n):
    return format(n, ',')


# ex.py
import utilityBill as ub

inputIncome = int(input('์ˆ˜์ž… ์ž…๋ ฅ: '))
ub.setIncome(inputIncome)

inputWaterPrice = int(input('์ˆ˜๋„์š”๊ธˆ ์ž…๋ ฅ: '))
ub.setWaterPrice(inputWaterPrice)

inputElectricPrice = int(input('์ „๊ธฐ์š”๊ธˆ ์ž…๋ ฅ: '))
ub.setElectricPrice(inputElectricPrice)

inputGasPrice = int(input('๊ฐ€์Šค์š”๊ธˆ ์ž…๋ ฅ: '))
ub.setGasPrice(inputGasPrice)

print(f'๊ณต๊ณผ๊ธˆ: {ub.formatedNumber(ub.getUtilityBill())}์›')
print(f'์ˆ˜์ž… ๋Œ€๋น„ ๊ณต๊ณผ๊ธˆ ๋น„์œจ: {ub.getUtilityBillRate()}%')

07 ํŒจํ‚ค์ง€์™€ ๋ชจ๋“ˆ์„ ๋งŒ๋“ค์–ด ์—ฐ์‚ฐ๊ฒฐ๊ณผ ์ถœ๋ ฅํ•˜๊ธฐ


# 1. arithmetic ํด๋” ์ƒ์„ฑ ํ›„ ์•ˆ์— basic_operator.py, developer_oerator.py ๋ชจ๋“ˆ ์ƒ์„ฑ

# basic_operator.py
def add(n1, n2):
    return round(n1 + n2, 2)

def sub(n1, n2):
    return round(n1 - n2, 2)

def mul(n1, n2):
    return round(n1 * n2, 2)

def div(n1, n2):
    return round(n1 / n2, 2)
    
# developer_oerator.py 
def mod(n1, n2):
    return round(n1 % n2, 2)

def flo(n1, n2):
    return round(n1 // n2, 2)

def exp(n1, n2):
    return round(n1 ** n2, 2)
    
# 2. shape ํด๋” ์ƒ์„ฑ ํ›„ ์•ˆ์— circle_area.py, triangle_square_area.py ๋ชจ๋“ˆ ์ƒ์„ฑ

# circle_area.py
def calCircleArea(r):
    return round(r ** 2 * 3.14, 2)
    
# triangle_square_area.py
def calTriangleArea(w, h):
    return round(w * h / 2, 2)

def calSquareArea(w, h):
    return round(w * h, 2)
    
# 3. arithmetic ํด๋”์™€ shape ํด๋” ๊ฒฝ๋กœ์— ์‹คํ–‰ํŒŒ์ผ ๋งŒ๋“ค๊ธฐ 
# ex.py
from arithmetic import basic_operator as bo
from arithmetic import developer_oerator as do

from shape import triangle_square_area as tsa
from shape import circle_area as ca


inputNumber1 = float(input('์ˆซ์ž1 ์ž…๋ ฅ: '))
inputNumber2 = float(input('์ˆซ์ž2 ์ž…๋ ฅ: '))

print(f'{inputNumber1} + {inputNumber2} = {bo.add(inputNumber1, inputNumber2)}')
print(f'{inputNumber1} - {inputNumber2} = {bo.sub(inputNumber1, inputNumber2)}')
print(f'{inputNumber1} * {inputNumber2} = {bo.mul(inputNumber1, inputNumber2)}')
print(f'{inputNumber1} / {inputNumber2} = {bo.div(inputNumber1, inputNumber2)}')

print(f'{inputNumber1} % {inputNumber2} = {do.mod(inputNumber1, inputNumber2)}')
print(f'{inputNumber1} // {inputNumber2} = {do.flo(inputNumber1, inputNumber2)}')
print(f'{inputNumber1} ** {inputNumber2} = {do.exp(inputNumber1, inputNumber2)}')


inputWidth = float(input('๊ฐ€๋กœ ๊ธธ์ด ์ž…๋ ฅ: '))
inputHeight = float(input('์„ธ๋กœ ๊ธธ์ด ์ž…๋ ฅ: '))

print(f'์‚ผ๊ฐํ˜• ๋„“์ด: {tsa.calTriangleArea(inputWidth, inputHeight)}')
print(f'์‚ฌ๊ฐํ˜• ๋„“์ด: {tsa.calSquareArea(inputWidth, inputHeight)}')

inputRadius = float(input('๋ฐ˜์ง€๋ฆ„ ์ž…๋ ฅ: '))
print(f'์‚ฌ๊ฐํ˜• ๋„“์ด: {ca.calCircleArea(inputRadius)}')

3. ํด๋ž˜์Šค (01~07)

01 ํšŒ์›๊ฐ€์ž… ํด๋ž˜์Šค์™€ ํšŒ์›์ •๋ณด๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ํšŒ์›๊ฐ€์ž… ๋กœ๊ทธ์ธ ๊ตฌํ˜„ํ•˜๊ธฐ

# member.py
class Member:
    def __init__(self, i, p):
        self.id = i
        self.pw = p


class MemberRepository:

    def __init__(self):
        self.members = {}

    def addMember(self, m):
        self.members[m.id] = m.pw

    def loginMember(self, i, p):
        isMember = i in self.members

        if isMember and self.members[i] == p:
            print(f'{i}: Log-in success!!')

        else:
            print(f'{i}: Log-in fail!!')

    def removeMember(self, i, p):
        del self.members[i]

    def printMembers(self):
        for mk in self.members.keys():
            print(f'ID: {mk}')
            print(f'PW: {self.members[mk]}')

# ex.py
import member as mb

mems = mb.MemberRepository()

for i in range(3):
    mId = input('์•„์ด๋”” ์ž…๋ ฅ: ')
    mPw = input('๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ: ')
    mem = mb.Member(mId, mPw)
    mems.addMember(mem)

mems.printMembers()


mems.loginMember('abc@gmail.com', '1234')
mems.loginMember('def@gmail.com', '5678')
mems.loginMember('ghi@gmail.com', '9012')

mems.removeMember('abc@gmail.com', '1234')

mems.printMembers()

02 TVํด๋ž˜์Šค๋ฅผ ์ƒ์†Œ๊ตฌ์กฐ๋กœ ๋งŒ๋“ค์–ด ๊ฐ์ฒด ์ƒ์„ฑํ•˜๊ธฐ

# smartTv.py
class NormalTv:

    def __init__(self, i=32, c='black', r='full-HD'):
        self.inch = i
        self.color = c
        self.resolution = r
        self.smartTv = 'off'
        self.aiTv = 'off'

    def turnOn(self):
        print('TV power on!!')

    def turnOff(self):
        print('TV power off!!')

    def printTvInfo(self):
        print(f'inch: {self.inch}inch')
        print(f'color: {self.color}')
        print(f'resolution: {self.resolution}')
        print(f'smartTv: {self.smartTv}')
        print(f'aiTv: {self.aiTv}')


class Tv4k(NormalTv):

    def __init__(self, i, c, r='4k'):
        super().__init__(i, c, r)

    def setSmartTv(self, s):
        self.smartTv = s


class Tv8k(NormalTv):

    def __init__(self, i, c, r='8k'):
        super().__init__(i, c, r)

    def setSmartTv(self, s):
        self.smartTv = s

    def setAiTv(self, a):
        self.aiTv = a


if __name__ == '__main__':
    my4KTv = Tv4k('65', 'silver', '4K')
    my4KTv.setSmartTv('on')
    my4KTv.turnOn()
    my4KTv.printTvInfo()
    my4KTv.turnOff()

    my8KTv = Tv8k('75', 'black', '8K')
    my8KTv.setSmartTv('on')
    my8KTv.setAiTv('on')
    my8KTv.turnOn()
    my8KTv.printTvInfo()
    my8KTv.turnOff()

# ex.py
import smartTv as st

my4KTv = st.Tv4k('65', 'silver', '4K')
my4KTv.setSmartTv('on')
my4KTv.turnOn()
my4KTv.printTvInfo()
my4KTv.turnOff()


friend4KTv = st.Tv4k('55', 'white', '4K')
friend4KTv.setSmartTv('off')
friend4KTv.turnOn()
friend4KTv.printTvInfo()
friend4KTv.turnOff()



my8KTv = st.Tv8k('75', 'black', '8K')
my8KTv.setSmartTv('on')
my8KTv.setAiTv('on')
my8KTv.turnOn()
my8KTv.printTvInfo()
my8KTv.turnOff()


friend8KTv = st.Tv8k('86', 'red', '8K')
friend8KTv.setSmartTv('on')
friend8KTv.setAiTv('off')
friend8KTv.turnOn()
friend8KTv.printTvInfo()
friend8KTv.turnOff()

03 ๋ช…์„ธ์„œ๋ฅผ ์ฐธ๊ณ ํ•ด ๋„์„œ ๊ด€๋ฆฌ ํ”„๋กœ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ

# book.py
class Book:

    def __init__(self, name, price, isbn):
        self.bName = name
        self.bPrice = price
        self.bIsbn = isbn


class BookRepository:

    def __init__(self):
        self.bDic = {}

    def registBook(self, b):
        self.bDic[b.bIsbn] = b

    def removeBook(self, isbn):
        del self.bDic[isbn]

    def printBooksInfo(self):
        for isbn in self.bDic.keys():
            b = self.bDic[isbn]
            print(f'{b.bName}, {b.bPrice}, {b.bIsbn}')

    def printBookInfo(self, isbn):
        if isbn in self.bDic:
            b = self.bDic[isbn]
            print(f'{b.bName}, {b.bPrice}, {b.bIsbn}')

        else:
            print('Lookup result does not exist')


if __name__ == '__main__':
    br = BookRepository()

    br.registBook(Book('python', 20000, '1234567890'))
    br.registBook(Book('java', 25000, '852147963'))
    br.registBook(Book('c/c++', 27000, '951378624'))
    br.registBook(Book('javascript', 15000, '9874563254'))

    br.printBooksInfo()
    br.printBookInfo('1234567890')
    br.removeBook('1234567890')
    br.printBooksInfo()

# ex.py
import book as bk

myBReposit = bk.BookRepository()

myBReposit.registBook(bk.Book('python', 20000, '1234567890'))
myBReposit.registBook(bk.Book('java', 25000, '852147963'))
myBReposit.registBook(bk.Book('c/c++', 27000, '951378624'))
myBReposit.registBook(bk.Book('javascript', 15000, '9874563254'))

myBReposit.printBooksInfo()
myBReposit.printBookInfo('1234567890')
myBReposit.removeBook('1234567890')
myBReposit.printBooksInfo()



friendBReposit = bk.BookRepository()

friendBReposit.registBook(bk.Book('python', 10000, '1234567890'))
friendBReposit.registBook(bk.Book('java', 15000, '852147963'))
friendBReposit.registBook(bk.Book('c/c++', 17000, '951378624'))
friendBReposit.registBook(bk.Book('javascript', 5000, '9874563254'))

friendBReposit.printBooksInfo()
friendBReposit.printBookInfo('1234567890')
friendBReposit.removeBook('1234567890')
friendBReposit.printBooksInfo()

04 ํ•œ์˜, ํ•œ์ผ ์‚ฌ์ „ ํด๋ž˜์Šค ๋งŒ๋“ค๊ธฐ (# ์ถ”์ƒํด๋ž˜์Šค #@)

# ADictionary.py
from abc import ABCMeta
from abc import abstractmethod

class AbsDictionary(metaclass=ABCMeta):

    def __init__(self):
        self.wordDic = {}

    @abstractmethod
    def registWord(self, w1, w2):
        pass

    @abstractmethod
    def removeWord(self, w1):
        pass

    @abstractmethod
    def updateWord(self, w1, w2):
        pass

    @abstractmethod
    def searchWord(self, w1):
        pass


class KorToEng(AbsDictionary):

    def __init__(self):
        super().__init__()

    def registWord(self, w1, w2):
        print(f'[KorToEng] registWord() : {w1} to {w2}')
        self.wordDic[w1] = w2

    def removeWord(self, w1):
        print(f'[KorToEng] removeWord() : {w1}')
        del self.wordDic[w1]

    def updateWord(self, w1, w2):
        print(f'[KorToEng] updateWord() : {w1} to {w2}')
        self.wordDic[w1] = w2

    def searchWord(self, w1):
        print(f'[KorToEng] searchWord() : {w1}')
        return self.wordDic[w1]

    def printWords(self):
        for k in self.wordDic:
            print(f'{k} : {self.wordDic[k]}')


class KorToJpa(AbsDictionary):

    def __init__(self):
        super().__init__()

    def registWord(self, w1, w2):
        print(f'[KorToJpa] registWord() : {w1} to {w2}')
        self.wordDic[w1] = w2

    def removeWord(self, w1):
        print(f'[KorToJpa] removeWord() : {w1}')
        del self.wordDic[w1]

    def updateWord(self, w1, w2):
        print(f'[KorToJpa] updateWord() : {w1} to {w2}')
        self.wordDic[w1] = w2

    def searchWord(self, w1):
        print(f'[KorToJpa] searchWord() : {w1}')
        return self.wordDic[w1]

    def printWords(self):
        for k in self.wordDic:
            print(f'{k} : {self.wordDic[k]}')


if __name__ == '__main__':
    kTe = KorToEng()
    
    # ๋‹จ์–ด ๋“ฑ๋ก
    kTe.registWord('์ฑ…', 'bok')
    kTe.registWord('๋‚˜๋น„', 'butterfly')
    kTe.registWord('์—ฐํ•„', 'pencil')
    kTe.registWord('ํ•™์ƒ', 'studen')
    kTe.registWord('์„ ์ƒ๋‹˜', 'teacher')

    # ๋‹จ์–ด ์ˆ˜์ •
    kTe.updateWord('์ฑ…', 'book')
    kTe.updateWord('ํ•™์ƒ', 'student')

    # ๋‹จ์–ด ๊ฒ€์ƒ‰
    print(f'์ฑ… : {kTe.searchWord("์ฑ…")}')
    print(f'๋‚˜๋น„ : {kTe.searchWord("๋‚˜๋น„")}')
    print(f'์—ฐํ•„ : {kTe.searchWord("์—ฐํ•„")}')
    print(f'ํ•™์ƒ : {kTe.searchWord("ํ•™์ƒ")}')
    print(f'์„ ์ƒ๋‹˜ : {kTe.searchWord("์„ ์ƒ๋‹˜")}')
    
    # ๋‹จ์–ด ์‚ญ์ œ
    kTe.removeWord('์ฑ…')

    # ์‚ฌ์ „ ์ถœ๋ ฅ
    kTe.printWords()

    
# ex.py
import ADictionary as dic

kTe = dic.KorToEng()

# ๋‹จ์–ด ๋“ฑ๋ก
kTe.registWord('์ฑ…', 'bok')
kTe.registWord('๋‚˜๋น„', 'butterfly')
kTe.registWord('์—ฐํ•„', 'pencil')
kTe.registWord('ํ•™์ƒ', 'studen')
kTe.registWord('์„ ์ƒ๋‹˜', 'teacher')

# ๋‹จ์–ด ์ˆ˜์ •
kTe.updateWord('์ฑ…', 'book')
kTe.updateWord('ํ•™์ƒ', 'student')

# ๋‹จ์–ด ๊ฒ€์ƒ‰
print(f'์ฑ… : {kTe.searchWord("์ฑ…")}')
print(f'๋‚˜๋น„ : {kTe.searchWord("๋‚˜๋น„")}')
print(f'์—ฐํ•„ : {kTe.searchWord("์—ฐํ•„")}')
print(f'ํ•™์ƒ : {kTe.searchWord("ํ•™์ƒ")}')
print(f'์„ ์ƒ๋‹˜ : {kTe.searchWord("์„ ์ƒ๋‹˜")}')

# ๋‹จ์–ด ์‚ญ์ œ
kTe.removeWord('์ฑ…')

# ์‚ฌ์ „ ์ถœ๋ ฅ
kTe.printWords()


kTj = dic.KorToJpa()

# ๋‹จ์–ด ๋“ฑ๋ก
kTj.registWord('์ฑ…', 'ๆœฌ')
kTj.registWord('๋‚˜๋น„', '่ถ')
kTj.registWord('์—ฐํ•„', '้‰›็ญ†')
kTj.registWord('ํ•™์ƒ', 'ๅญฆ็”Ÿ')
kTj.registWord('์„ ์ƒ๋‹˜', 'ๅ…ˆ็”Ÿ')

# ๋‹จ์–ด ์ˆ˜์ •
kTj.updateWord('์ฑ…', '่ถ')
kTj.updateWord('ํ•™์ƒ', 'ๅญฆ็”Ÿ')

# ๋‹จ์–ด ๊ฒ€์ƒ‰
print(f'์ฑ… : {kTj.searchWord("์ฑ…")}')
print(f'๋‚˜๋น„ : {kTj.searchWord("๋‚˜๋น„")}')
print(f'์—ฐํ•„ : {kTj.searchWord("์—ฐํ•„")}')
print(f'ํ•™์ƒ : {kTj.searchWord("ํ•™์ƒ")}')
print(f'์„ ์ƒ๋‹˜ : {kTj.searchWord("์„ ์ƒ๋‹˜")}')

# ๋‹จ์–ด ์‚ญ์ œ
kTj.removeWord('์ฑ…')

# ์‚ฌ์ „ ์ถœ๋ ฅ
kTj.printWords()

05 ์ฃผ์‚ฌ์œ„ ๊ฒŒ์ž„ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ์ปดํ“จํ„ฐ์™€ ์‚ฌ์šฉ์ž์˜ ๊ฒŒ์ž„ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜๊ธฐ

# dice.py
import random as rd

class Dice:

    def __init__(self):
        self.cNum = 0
        self.uNum = 0

    def setCnum(self):
        print('[Dice] setCnum()')
        self.cNum = rd.randint(1, 6)

    def setUnum(self):
        print('[Dice] setUnum()')
        self.uNum = rd.randint(1, 6)

    def startGame(self):
        print('[Dice] startGame()')
        self.setCnum()
        self.setUnum()

    def printResult(self):
        print('[Dice] printResult()')

        if self.cNum == 0 or self.uNum == 0:
            print('์ฃผ์‚ฌ์œ„ ์ˆซ์ž ์„ค์ • ์ „ ์ž…๋‹ˆ๋‹ค.')

        else:
            if self.cNum > self.uNum:
                print(f'์ปดํ“จํ„ฐ vs ์œ ์ € : {self.cNum} vs {self.uNum} >> ์ปดํ“จํ„ฐ ์Šน!!')

            elif self.cNum < self.uNum:
                print(f'์ปดํ“จํ„ฐ vs ์œ ์ € : {self.cNum} vs {self.uNum} >> ์œ ์ € ์Šน!!')

            elif self.cNum == self.uNum:
                print(f'์ปดํ“จํ„ฐ vs ์œ ์ € : {self.cNum} vs {self.uNum} >> ๋ฌด์Šน๋ถ€!!')


if __name__ == '__main__':
    dc = Dice()
    dc.startGame()
    dc.printResult()

# ex.py
import dice

dc = dice.Dice()
dc.startGame()
dc.printResult()

06 ์ž๋™์ฐจ ๊ฒฝ์ฃผ ๊ฒŒ์ž„ ํด๋ž˜์Šค ๋งŒ๋“ค๊ธฐ

# 1. car_game ํด๋” ๋งŒ๋“  ํ›„ car.py, racing.py ์ƒ์„ฑ

# car.py
import random

class Car:

    def __init__(self, n='fire car', c='red', s=200):
        self.name = n
        self.color = c
        self.max_speed = s
        self.distance = 0

    def printCarInfo(self):
        print(f'name: {self.name}, '
              f'color: {self.color}, '
              f'max_speed: {self.max_speed}, '
              f'current_speed: {self.cur_speed}')

    def controlSpeed(self):
        return random.randint(0, self.max_speed)

    def getDistanceForHour(self):
        return self.controlSpeed() * 1



if __name__ == '__main__':
    tempCar = Car('myCar', 'black', 250)
    tempCar.printCarInfo()
    print(tempCar.controlSpeed())

# racing.py
from time import sleep

class CarRacing:

    def __init__(self):
        self.cars = []
        self.rankings = []

    def startRacing(self):
        for i in range(10):
            print(f'Racing: {i+1}๋ฐ”ํ€ด')
            for car in self.cars:
                car.distance += car.getDistanceForHour()

            sleep(1)
            self.printCurrentCarDistance()

    def printCurrentCarDistance(self):
        for car in self.cars:
            print(f'{car.name}: {car.distance}\t\t', end='')
        print()

    def addCar(self, c):
        self.cars.append(c)
        
# 2. car_game ํด๋” ๊ฒฝ๋กœ์— ex.py ํŒŒ์ผ ์ƒ์„ฑ

from car_game import racing as rc
from car_game import car

myCarGame = rc.CarRacing()
car01 = car.Car('Car01', 'white', 250)
car02 = car.Car('Car02', 'black', 200)
car03 = car.Car('Car03', 'yellow', 220)
car04 = car.Car('Car04', 'red', 280)
car05 = car.Car('Car05', 'blue', 150)

myCarGame.addCar(car01)
myCarGame.addCar(car02)
myCarGame.addCar(car03)
myCarGame.addCar(car04)
myCarGame.addCar(car05)

myCarGame.startRacing()

07 mp3 ํ”Œ๋ ˆ์ด์–ด ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ๋…ธ๋ž˜ ๋“ฑ๋ก ํ›„ ์žฌ์ƒํ•˜๊ธฐ

# mp3player.py
import random
from time import sleep

class Song:

    def __init__(self, t, s, pt):
        self.title = t
        self.singer = s
        self.play_time = pt

    def printSongInfo(self):
        print(f'Title: {self.title}, Singer: {self.singer}, Play time: {self.play_time}')


class Player:

    def __init__(self):
        self.songList = []
        self.isLoop = False

    def addSong(self, s):
        self.songList.append(s)

    def play(self):
        if self.isLoop:
            while self.isLoop:
                for s in self.songList:
                    print(f'Title: {s.title}, Singer: {s.singer}, Play time: {s.play_time}sec')
                    sleep(s.play_time)
        else:
            for s in self.songList:
                print(f'Title: {s.title}, Singer: {s.singer}, Play time: {s.play_time}sec')
                sleep(s.play_time)

    def suffle(self):
        random.shuffle(self.songList)

    def setIsLoop(self, flag):
        self.isLoop = flag


# ex.py
import mp3player as mp3

s1 = mp3.Song('์‹ ํ˜ธ๋“ฑ', '์ด๋ฌด์ง„', 3)
s2 = mp3.Song('Permission to Dance', '๋ฐฉํƒ„์†Œ๋…„๋‹จ', 4)
s3 = mp3.Song('Butter', '๋ฐฉํƒ„์†Œ๋…„๋‹จ', 2)
s4 = mp3.Song('Weekend', 'TAEYEON', 5)
s5 = mp3.Song('์ข‹์•„์ข‹์•„', '์กฐ์ •์„', 4)

player = mp3.Player()
player.addSong(s1)
player.addSong(s2)
player.addSong(s3)
player.addSong(s4)
player.addSong(s5)

player.setIsLoop(False)
player.suffle()
player.play()

4. ์˜ˆ์™ธ์ฒ˜๋ฆฌ(01~05)

01 ์‚ฐ์ˆ ์—ฐ์‚ฐ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜๊ณ  ์˜ˆ์ƒ๋˜๋Š” ์˜ˆ์™ธ์ฒ˜๋ฆฌ ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ

# calculator.py
def add(n1, n2):
    print('๋ง์…ˆ ์—ฐ์‚ฐ')
    try:
        n1 = float(n1)
    except:
        print('์ฒซ ๋ฒˆ์งธ ํ”ผ์—ฐ์‚ฐ์ž๋Š” ์ˆซ์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.')
        return

    try:
        n2 = float(n2)
    except:
        print('๋‘ ๋ฒˆ์งธ ํ”ผ์—ฐ์‚ฐ์ž๋Š” ์ˆซ์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.')
        return

    print(f'{n1} + {n2} = {n1 + n2}')


def sub(n1, n2):
    print('๋บ„์…ˆ ์—ฐ์‚ฐ')
    try:
        n1 = float(n1)
    except:
        print('์ฒซ ๋ฒˆ์งธ ํ”ผ์—ฐ์‚ฐ์ž๋Š” ์ˆซ์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.')
        return

    try:
        n2 = float(n2)
    except:
        print('๋‘ ๋ฒˆ์งธ ํ”ผ์—ฐ์‚ฐ์ž๋Š” ์ˆซ์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.')
        return

    print(f'{n1} - {n2} = {n1 - n2}')


def mul(n1, n2):
    print('๊ณฑ์…ˆ ์—ฐ์‚ฐ')
    try:
        n1 = float(n1)
    except:
        print('์ฒซ ๋ฒˆ์งธ ํ”ผ์—ฐ์‚ฐ์ž๋Š” ์ˆซ์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.')
        return

    try:
        n2 = float(n2)
    except:
        print('๋‘ ๋ฒˆ์งธ ํ”ผ์—ฐ์‚ฐ์ž๋Š” ์ˆซ์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.')
        return

    print(f'{n1} * {n2} = {n1 * n2}')


def div(n1, n2):
    print('๋‚˜๋ˆ—์…ˆ ์—ฐ์‚ฐ')
    try:
        n1 = float(n1)
    except:
        print('์ฒซ ๋ฒˆ์งธ ํ”ผ์—ฐ์‚ฐ์ž๋Š” ์ˆซ์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.')
        return

    try:
        n2 = float(n2)
    except:
        print('๋‘ ๋ฒˆ์งธ ํ”ผ์—ฐ์‚ฐ์ž๋Š” ์ˆซ์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.')
        return

    if n2 == 0:
        print('0์œผ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.')
        return

    print(f'{n1} / {n2} = {n1 / n2}')
    
    # try:
    #     print(f'{n1} / {n2} = {n1 / n2}')
    # except ZeroDivisionError as e:
    #     print(e)
    #     print('0์œผ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.')
    

def mod(n1, n2):
    print('๋‚˜๋จธ์ง€ ์—ฐ์‚ฐ')
    try:
        n1 = float(n1)
    except:
        print('์ฒซ ๋ฒˆ์งธ ํ”ผ์—ฐ์‚ฐ์ž๋Š” ์ˆซ์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.')
        return

    try:
        n2 = float(n2)
    except:
        print('๋‘ ๋ฒˆ์งธ ํ”ผ์—ฐ์‚ฐ์ž๋Š” ์ˆซ์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.')
        return

    if n2 == 0:
        print('0์œผ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.')
        return

    print(f'{n1} % {n2} = {n1 % n2}')


def flo(n1, n2):
    print('๋ชซ ์—ฐ์‚ฐ')
    try:
        n1 = float(n1)
    except:
        print('์ฒซ ๋ฒˆ์งธ ํ”ผ์—ฐ์‚ฐ์ž๋Š” ์ˆซ์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.')
        return

    try:
        n2 = float(n2)
    except:
        print('๋‘ ๋ฒˆ์งธ ํ”ผ์—ฐ์‚ฐ์ž๋Š” ์ˆซ์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.')
        return

    if n2 == 0:
        print('0์œผ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.')
        return

    print(f'{n1} // {n2} = {int(n1 // n2)}')


def exp(n1, n2):
    print('๊ฑฐ๋“ญ์ œ๊ณฑ ์—ฐ์‚ฐ')
    try:
        n1 = float(n1)
    except:
        print('์ฒซ ๋ฒˆ์งธ ํ”ผ์—ฐ์‚ฐ์ž๋Š” ์ˆซ์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.')
        return

    try:
        n2 = float(n2)
    except:
        print('๋‘ ๋ฒˆ์งธ ํ”ผ์—ฐ์‚ฐ์ž๋Š” ์ˆซ์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.')
        return

    print(f'{n1} ** {n2} = {n1 ** n2}')

# ex.py
import calculator as cc

num1 = input('์ฒซ ๋ฒˆ์งธ ํ”ผ์—ฐ์‚ฐ์ž ์ž…๋ ฅ: ')
num2 = input('๋‘ ๋ฒˆ์งธ ํ”ผ์—ฐ์‚ฐ์ž ์ž…๋ ฅ: ')

cc.add(num1, num2)
cc.sub(num1, num2)
cc.mul(num1, num2)
cc.div(num1, num2)
cc.mod(num1, num2)
cc.flo(num1, num2)
cc.exp(num1, num2)

02 1๋ถ€ํ„ฐ 1000๊นŒ์ง€์˜ ์†Œ์ˆ˜์ธ ๋‚œ์ˆ˜๋ฅผ 10๊ฐœ ์ƒ์„ฑํ•˜๋˜ ์†Œ๊ตฌ๊ฐ€ ์•„๋‹ˆ๋ฉด ์‚ฌ์šฉ์ž ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•˜๋„๋ก ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ

# prime_module.py
class NotPrimeException(Exception):

    def __init__(self, n):
        super().__init__(f'{n} is not prime number.')


class PrimeException(Exception):

    def __init__(self, n):
        super().__init__(f'{n} is prime number.')


def isPrime(number):
    flag = True
    for n in range(2, number):
        if number % n == 0:
            flag = False
            break

    if flag == False:
        raise NotPrimeException(number)
    else:
        raise PrimeException(number)

# ex.py
import random
import prime_module as pm

primeNumbers = []

n = 0
while n < 10:

    rn = random.randint(2, 1000)
    if rn not in primeNumbers:

        try:
            pm.isPrime(rn)

        except pm.NotPrimeException as e:
            print(e)
            continue

        except pm.PrimeException as e:
            print(e)
            primeNumbers.append(rn)

    else:
        print(f'{rn} is overlap number.')
        continue

    n += 1


print(f'PrimeNumbers: {primeNumbers}')

03 ์ด๊ตฌ๋งค๊ธˆ์•ก์„ ์ถœ๋ ฅํ•˜๋˜ ๊ฐœ์ˆ˜๊ฐ€ ์ž˜๋ชป ์ž…๋ ฅ๋œ ๊ฒฝ์šฐ ๋ณ„๋„๋กœ ์ถœ๋ ฅํ•˜๋„๋ก ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ

# calculatePurchase.py
g1price = 1200; g2price = 1000; g3price = 800
g4price = 2000; g5price = 900

def formatedNumber(n):
    return format(n, ',')

def calculate(*gcs):

    gcsDic = {}
    againCntInput = {}

    for idx, gc in enumerate(gcs):
        try:
            gcsDic[f'g{idx+1}'] = int(gc)
        except Exception as e:
            againCntInput[f'g{idx+1}'] = gc
            print(e)

    totalPrice = 0
    for g in gcsDic.keys():
        totalPrice += globals()[f'{g}price'] * gcsDic[g]

    print('---------------------------')
    print(f'์ด ๊ตฌ๋งค ๊ธˆ์•ก: {formatedNumber(totalPrice)}์›')
    print('-------- ๋ฏธ๊ฒฐ์ œ ํ•ญ๋ชฉ --------')
    for g in againCntInput.keys():
        print(f'์ƒํ’ˆ: {g},\t ๊ตฌ๋งค ๊ฐœ์ˆ˜: {againCntInput[g]}')
    print('---------------------------')

# ex.py
import calculatePurchase as cp

g1Cnt = input('goods1 ๊ตฌ๋งค ๊ฐœ์ˆ˜: ')
g2Cnt = input('goods2 ๊ตฌ๋งค ๊ฐœ์ˆ˜: ')
g3Cnt = input('goods3 ๊ตฌ๋งค ๊ฐœ์ˆ˜: ')
g4Cnt = input('goods4 ๊ตฌ๋งค ๊ฐœ์ˆ˜: ')
g5Cnt = input('goods5 ๊ตฌ๋งค ๊ฐœ์ˆ˜: ')

cp.calculate(g1Cnt, g2Cnt, g3Cnt, g4Cnt, g5Cnt)

04 ํšŒ์› ๊ฐ€์ž… ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค๋˜ ์ž…๋ ฅํ•˜์ง€ ์•Š์€ ํ•ญ๋ชฉ์ด ์žˆ๋Š” ๊ฒฝ์šฐ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ

# mem.py
class EmptyDataException(Exception):

    def __init__(self, i):
        super().__init__(f'{i} is empty!')

def checkInputData(n, m, p, a, ph):

    if n == '':
        raise EmptyDataException('name')
    elif m == '':
        raise EmptyDataException('mail')
    elif p == '':
        raise EmptyDataException('password')
    elif a == '':
        raise EmptyDataException('address')
    elif ph == '':
        raise EmptyDataException('phone')
    else:
        return True

class RegisteMember():

    def __init__(self, n, m, p, a, ph):
        self.m_name = n
        self.m_mail = m
        self.m_pw = p
        self.m_addr = a
        self.m_phone = ph
        print('Membership completed!!')

    def printMemberInfo(self):
        print(f'm_name: {self.m_name}')
        print(f'm_mail: {self.m_mail}')
        print(f'm_pw: {self.m_pw}')
        print(f'm_addr: {self.m_addr}')
        print(f'm_phone: {self.m_phone}')
        
# ex.py
import  mem

m_name = input('์ด๋ฆ„ ์ž…๋ ฅ: ')
m_mail = input('๋ฉ”์ผ ์ฃผ์†Œ ์ž…๋ ฅ: ')
m_pw = input('๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ: ')
m_addr = input('์ฃผ์†Œ ์ž…๋ ฅ: ')
m_phone = input('์—ฐ๋ฝ์ฒ˜ ์ž…๋ ฅ: ')

try:
    mem.checkInputData(m_name, m_mail, m_pw, m_addr, m_phone)
    newMember = mem.RegisteMember(m_name, m_mail, m_pw, m_addr, m_phone)
    newMember.printMemberInfo()

except mem.EmptyDataException as e:
    print(e)

05 ์€ํ–‰ ๊ณ„์ขŒ ๊ฐœ์„ค ๋ฐ ์ž…/์ถœ๊ธˆ ํ”„๋กœ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ

# bank.py
import random

class PrivateBank:

    def __init__(self, bank, account_name):
        self.bank = bank
        self.account_name = account_name

        while True:
            newAccountNo = random.randint(10000, 99999)
            if bank.isAccount(newAccountNo):
                continue
            else:
                self.account_no = newAccountNo
                break

        self.totalMoney = 0
        bank.addAccount(self)

    def printBankInfo(self):
        print('-' * 40)
        print(f'account_name: {self.account_name}')
        print(f'account_no: {self.account_no}')
        print(f'totalMoney: {self.totalMoney}์›')
        print('-' * 40)


class Bank:

    def __init__(self):
        self.accounts = {}

    def addAccount(self, privateBank):
        self.accounts[privateBank.account_no] = privateBank

    def isAccount(self, ano):
        return ano in self.accounts

    def doDeposit(self, ano, m):
        pb = self.accounts[ano]
        pb.totalMoney = pb.totalMoney + m

    def doWithdraw(self, ano, m):
        pb = self.accounts[ano]
        if pb.totalMoney - m < 0:
            raise LackException(pb.totalMoney, m)
        pb.totalMoney = pb.totalMoney - m


class LackException(Exception):
    def __init__(self, m1, m2):
        super().__init__(f'์ž”๊ณ ๋ถ€์กฑ!!, ์ž”์•ก: {m1}, ์ถœ๊ธˆ์•ก: {m2}')

# ex.py
import bank

koreaBank = bank.Bank()

new_account_name = input('ํ†ต์žฅ ๊ณ„์„ค์„ ์œ„ํ•œ ์˜ˆ๊ธˆ์ฃผ ์ž…๋ ฅ: ')
myAccount = bank.PrivateBank(koreaBank, new_account_name)
myAccount.printBankInfo()

while True:

    selectNumber = int(input('1.์ž…๊ธˆ, \t2.์ถœ๊ธˆ, \t3.์ข…๋ฃŒ '))
    if selectNumber == 1:
        m = int(input('์ž…๊ธˆ์•ก ์ž…๋ ฅ: '))
        koreaBank.doDeposit(myAccount.account_no, m)
        myAccount.printBankInfo()

    elif selectNumber == 2:
        m = int(input('์ถœ๊ธˆ์•ก ์ž…๋ ฅ: '))
        try:
            koreaBank.doWithdraw(myAccount.account_no, m)
        except bank.LackException as e:
            print(e)
        finally:
            myAccount.printBankInfo()
    elif selectNumber == 3:
        print('Bye~')
        break

    else:
        print('์ž˜๋ชป ์ž…๋ ฅํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์„ ํƒํ•˜์„ธ์š”. ')

5. ํ…์ŠคํŠธํŒŒ์ผ(01~05)

01 ํšŒ์› ๊ณ„์ •๋ณ„ ํ…์ŠคํŠธ ํŒŒ์ผ์„ ์ƒ์„ฑํ•œ ํ›„ ํšŒ์› ๋ณธ์ธ ํŒŒ์ผ์— ํ•œ์ค„ ์ผ๊ธฐ๋ฅผ ์“ฐ๊ณ  ์ฝ๋Š” ํ”„๋กœ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ

# diary.py
import time

def writeDiary(u, f, d):
    lt = time.localtime()
    timeStr = time.strftime('%Y-%m-%d %I:%M:%S %p', lt)

    filePath = u + f
    with open(filePath, 'a') as f:
        f.write(f'[{timeStr}] {d}\n')

def readDiary(u, f):
    lt = time.localtime()
    timeStr = time.strftime('%Y-%m-%d %I:%M:%S %p', lt)

    filePath = u + f
    datas = []
    with open(filePath, 'r') as f:
        datas = f.readlines()

    return datas
    
# ex.py
import diary

members = {}
uri = 'C:/pythonTxt/'

def printMembers():
    for m in members.keys():
        print(f'ID: {m} \t PW: {members[m]}')

while True:

    selectNum = int(input('1.ํšŒ์›๊ฐ€์ž…,\t 2.ํ•œ์ค„์ผ๊ธฐ์“ฐ๊ธฐ,\t 3.ํ•œ์ค„์ผ๊ธฐ๋ณด๊ธฐ,\t 4.์ข…๋ฃŒ '))

    if(selectNum == 1):
        mId = input('input ID: ')
        mPw = input('input PW: ')
        members[mId] = mPw
        printMembers()

    elif(selectNum == 2):
        mId = input('input ID: ')
        mPw = input('input PW: ')

        if mId in members and members[mId] == mPw:
            print('login success!!')
            fileName = 'myDaiary_' + mId + '.txt'
            data = input('์˜ค๋Š˜ ํ•˜๋ฃจ ์ธ์ƒ ๊นŠ์€ ์ผ์„ ๊ธฐ๋กํ•˜์„ธ์š”. ')
            diary.writeDiary(uri, fileName, data)

        else:
            print('login fail!!')
            printMembers()

    elif (selectNum == 3):
        mId = input('input ID: ')
        mPw = input('input PW: ')

        if mId in members and members[mId] == mPw:
            print('login success!!')
            fileName = 'myDaiary_' + mId + '.txt'
            datas = diary.readDiary(uri, fileName)
            for d in datas:
                print(d, end='')

        else:
            print('login fail!!')
            printMembers()

    elif (selectNum == 4):
        print('Bye~')
        break

02 ์ˆ˜์ž…๊ณผ ์ง€์ถœ์„ ๊ธฐ๋กํ•˜๋Š” ๊ฐ€๊ณ„๋ถ€ ๋งŒ๋“ค๊ธฐ

import time

limitSpendMoney = 2000


def getTime():
    lt = time.localtime()
    st = time.strftime('%Y-%m-%d %H:%M:%S')
    return st


while True:

    selectNumber = int(input('1.์ž…๊ธˆ \t 2.์ถœ๊ธˆ \t 3.์ข…๋ฃŒ '))

    if selectNumber == 1:
        money = int(input('์ž…๊ธˆ์•ก ์ž…๋ ฅ: '))
        with open('C:/pythonTxt/bank/money.txt', 'r') as f:
            m = f.read()

        with open('C:/pythonTxt/bank/money.txt', 'w') as f:
            f.write(str(int(m) + money))

        memo = input('์ž…๊ธˆ ๋‚ด์—ญ ์ž…๋ ฅ: ')
        with open('C:/pythonTxt/bank/pocketMoneyRegister.txt', 'a') as f:
            f.write('-------------------------------------------\n')
            f.write(f'{getTime()} \n')
            f.write(f'[์ž…๊ธˆ] {memo} : {str(money)}์› \n')
            f.write(f'[์ž”์•ก] {str(int(m) + money)}์› \n')

        print('์ž…๊ธˆ ์™„๋ฃŒ!!')
        print(f'๊ธฐ์กด ์ž”์•ก : {m}')
        print(f'์ž…๊ธˆ ํ›„ ์ž”์•ก : {int(m) + money}')


    elif selectNumber == 2:
        money = int(input('์ถœ๊ธˆ์•ก ์ž…๋ ฅ: '))
        with open('C:/pythonTxt/bank/money.txt', 'r') as f:
            m = f.read()

        with open('C:/pythonTxt/bank/money.txt', 'w') as f:
            f.write(str(int(m) - money))

        memo = input('์ถœ๊ธˆ ๋‚ด์—ญ ์ž…๋ ฅ: ')
        with open('C:/pythonTxt/bank/pocketMoneyRegister.txt', 'a') as f:
            f.write('-------------------------------------------\n')
            f.write(f'{getTime()} \n')
            f.write(f'[์ถœ๊ธˆ] memo : {str(money)}์› \n')
            f.write(f'[์ž”์•ก] {str(int(m) - money)}์› \n')

        print('์ถœ๊ธˆ ์™„๋ฃŒ!!')
        print(f'๊ธฐ์กด ์ž”์•ก : {m}')
        print(f'์ถœ๊ธˆ ํ›„ ์ž”์•ก : {int(m) - money}')

    elif selectNumber == 3:
        print('Bye~')
        break

    else:
        print('์ž˜๋ชป ์ž…๋ ฅํ•˜์…จ์Šต๋‹ˆ๋‹ค.')

03 ์ˆซ์ž์˜ ์•ฝ์ˆ˜์™€ ์†Œ์ˆ˜๋ฅผ ํ…์ŠคํŠธ ํŒŒ์ผ์— ๊ธฐ๋กํ•˜๊ธฐ (2๋ฌธ)

# ์•ฝ์ˆ˜
inputNumber = int(input("0๋ณด๋‹ค ํฐ ์ •์ˆ˜ ์ž…๋ ฅ: "))

divisor = []
for number in range(1, (inputNumber + 1)):
    if inputNumber % number == 0:
        divisor.append(number)

if len(divisor) > 0:
    try:
        with open('C:/pythonTxt/divisor.txt', 'a') as f:
            f.write(f'{inputNumber}์˜ ์•ฝ์ˆ˜: ')
            f.write(f'{divisor}\n')

    except Exception as e:
        print(e)

    else:
        print('divisor write complete!')


#์†Œ์ˆ˜
inputNumber = int(input("0๋ณด๋‹ค ํฐ ์ •์ˆ˜ ์ž…๋ ฅ: "))

prime = []
for number in range(2, (inputNumber + 1)):
    flag = True
    for n in range(2, number):
        if number % n == 0:
            flag = False
            break

    if (flag):
        prime.append(number)

if len(prime) > 0:
    try:
        with open('C:/pythonTxt/prime.txt', 'a') as f:
            f.write(f'{inputNumber}๊นŒ์ง€์˜ ์†Œ์ˆ˜: ')
            f.write(f'{prime}\n')

    except Exception as e:
        print(e)

    else:
        print('prime write complete!')

04 ๋‘๊ฐœ์˜ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๊ณต์•ฝ์ˆ˜, ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜๋ฅผ ํ…์ŠคํŠธ ํŒŒ์ผ์— ์ž‘์„ฑํ•˜๊ธฐ (3๋ฌธ)


# ์ˆ˜ ๋‘๊ฐœ์˜ ๊ณต์•ฝ์ˆ˜
num1 = int(input('1๋ณด๋‹ค ํฐ ์ •์ˆ˜ ์ž…๋ ฅ: '))
num2 = int(input('1๋ณด๋‹ค ํฐ ์ •์ˆ˜ ์ž…๋ ฅ: '))

common = []
for i in range(1, (num1 + 1)):
    if num1 % i == 0 and num2 % i == 0:
        common.append(i)

if len(common) > 0:
    try:
        with open('C:/pythonTxt/common.txt', 'a') as f:
            f.write(f'{num1}์™€ {num2}์˜ ๊ณต์•ฝ์ˆ˜: ')
            f.write(f'{common}\n')

    except Exception as e:
        print(e)

    else:
        print('common factor write complete!')


# ์ˆ˜ ๋‘๊ฐœ์˜ ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜
num1 = int(input('1๋ณด๋‹ค ํฐ ์ •์ˆ˜ ์ž…๋ ฅ: '))
num2 = int(input('1๋ณด๋‹ค ํฐ ์ •์ˆ˜ ์ž…๋ ฅ: '))
maxComNum = 0

for i in range(1, (num1 + 1)):
    if num1 % i == 0 and num2 % i == 0:
        maxNum = i

try:
    with open('C:/pythonTxt/maxComNum.txt', 'a') as f:
        f.write(f'{num1}์™€ {num2}์˜ ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜: {maxNum}\n')

except Exception as e:
    print(e)

else:
    print('max common factor write complete!')



# ์ˆ˜ ์„ธ๊ฐœ์˜ ๊ณต์•ฝ์ˆ˜
num1 = int(input('1๋ณด๋‹ค ํฐ ์ •์ˆ˜ ์ž…๋ ฅ: '))
num2 = int(input('1๋ณด๋‹ค ํฐ ์ •์ˆ˜ ์ž…๋ ฅ: '))
num3 = int(input('1๋ณด๋‹ค ํฐ ์ •์ˆ˜ ์ž…๋ ฅ: '))

common = []
for i in range(1, (num1 + 1)):
    if num1 % i == 0 and num2 % i == 0 and num3 % i == 0:
        common.append(i)

if len(common) > 0:
    try:
        with open('C:/pythonTxt/common.txt', 'a') as f:
            f.write(f'{num1}, {num2}, {num3}์˜ ๊ณต์•ฝ์ˆ˜: ')
            f.write(f'{common}\n')

    except Exception as e:
        print(e)

    else:
        print('common factor write complete!')

#์ˆ˜ ์„ธ๊ฐœ์˜ ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜
num1 = int(input('1๋ณด๋‹ค ํฐ ์ •์ˆ˜ ์ž…๋ ฅ: '))
num2 = int(input('1๋ณด๋‹ค ํฐ ์ •์ˆ˜ ์ž…๋ ฅ: '))
num3 = int(input('1๋ณด๋‹ค ํฐ ์ •์ˆ˜ ์ž…๋ ฅ: '))
maxComNum = 0

for i in range(1, (num1 + 1)):
    if num1 % i == 0 and num2 % i == 0 and num3 % i == 0:
        maxComNum = i

try:
    with open('C:/pythonTxt/maxComNum.txt', 'a') as f:
        f.write(f'{num1}, {num2}, {num3}์˜ ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜: {maxComNum}\n')

except Exception as e:
    print(e)

else:
    print('max common factor write complete!')

05 ๋ฐฐ(๊ณผ์ผ)๊ฐ€ ์ž…ํ•ญํ•˜๋Š” ๋‚ ์งœ๋ฅผ ํ…์ŠคํŠธ ํŒŒ์ผ์— ๊ธฐ๋กํ•ด๋ณด๊ธฐ

ship1 = 3; ship2 = 4; ship3 = 5
maxDay = 0

for i in range(1, (ship1 + 1)):
    if ship1 % i == 0 and ship2 % i == 0:
        maxDay = i

# print('์ตœ๋Œ€๊ณต์•ฝ์ˆ˜: {}'.format(maxDay))

minDay = (ship1 * ship2) // maxDay
# print('{}, {}์˜ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜: {}'.format(ship1, ship2, minDay))


newDay = minDay
for i in range(1, (newDay + 1)):
    if newDay % i == 0 and ship3 % i == 0:
        maxDay = i

# print('์ตœ๋Œ€๊ณต์•ฝ์ˆ˜: {}'.format(maxDay))

minDay = (newDay * ship3) // maxDay
# print('{}, {}, {}์˜ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜: {}'.format(ship1, ship2, ship3, minDay))

# print('{}์ผ๋งˆ๋‹ค ๋ชจ๋“  ์„ ๋ฐ•์ด ์ž…ํ•ญํ•ฉ๋‹ˆ๋‹ค.'.format(minDay))


from datetime import datetime
from datetime import timedelta

n = 1
baseTime = datetime(2021, 1, 1, 10, 0, 0)
# baseTime = datetime.now()

# print(f'2021๋…„ ๋ชจ๋“  ์„ ๋ฐ• ์ž…ํ•ญ์ผ: {baseTime}')
with open('C:/pythonTxt/arrive.txt', 'a') as f:
    f.write(f'2021๋…„ ๋ชจ๋“  ์„ ๋ฐ• ์ž…ํ•ญ์ผ\n')
    f.write(f'{baseTime}\n')

nextTime = baseTime + timedelta(days=minDay)
while True:

    # print(f'2021๋…„ ๋ชจ๋“  ์„ ๋ฐ• ์ž…ํ•ญ์ผ: {nextTime}')
    with open('C:/pythonTxt/arrive.txt', 'a') as f:
        f.write(f'{nextTime}\n')

    nextTime = nextTime + timedelta(days=minDay)
    if nextTime.year > 2021:
        break

0๊ฐœ์˜ ๋Œ“๊ธ€