python

ยทpython
ํŒŒ์ด์ฌ์œผ๋กœ ๊ธฐ์ดˆ์ ์ธ ํ”„๋กœ๊ทธ๋žจ์„ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ํ•˜๋‹ค ๋ณด๋ฉด, ์˜ค๋ฅ˜๋ฅผ ํ•ธ๋“ค๋ง ํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์Šต๋‹ˆ๋‹ค.  When user enters invalid input, it is common to abort the program. ๊ทธ๋ ‡๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”, sys standard library module์— ์ •์˜๋œ exit ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. from sys import exitif not (userResponse == "n" or userResponse == "y"): exit("Error: you must enter either n or y.") exit(errorMessage) ํ˜•์‹์œผ๋กœ ํ”„๋กœ๊ทธ๋žจ terminate ์‹œ์— ์ถœ๋ ฅ๋  ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ์ธ์ž๋กœ ๋„ฃ์œผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.
ยทpython
There are some ways in Python to analyze string.  substring in sReturns True if the string s contains substring and False otherwise.if "-" is not in name: ...s.count(substring)Returns the number of non-overlapping occurrences of substring in s.s.endswith(substring)Returns True if the string s ends with the substring and False otherwise.s.startswith(substring)Returns True if the string s starts w..
ยทpython
https://www.acmicpc.net/problem/2563 2563๋ฒˆ: ์ƒ‰์ข…์ด ๊ฐ€๋กœ, ์„ธ๋กœ์˜ ํฌ๊ธฐ๊ฐ€ ๊ฐ๊ฐ 100์ธ ์ •์‚ฌ๊ฐํ˜• ๋ชจ์–‘์˜ ํฐ์ƒ‰ ๋„ํ™”์ง€๊ฐ€ ์žˆ๋‹ค. ์ด ๋„ํ™”์ง€ ์œ„์— ๊ฐ€๋กœ, ์„ธ๋กœ์˜ ํฌ๊ธฐ๊ฐ€ ๊ฐ๊ฐ 10์ธ ์ •์‚ฌ๊ฐํ˜• ๋ชจ์–‘์˜ ๊ฒ€์€์ƒ‰ ์ƒ‰์ข…์ด๋ฅผ ์ƒ‰์ข…์ด์˜ ๋ณ€๊ณผ ๋„ํ™”์ง€์˜ ๋ณ€์ด ํ‰ํ–‰ํ•˜๋„๋ก www.acmicpc.net ์ฝ”๋“œ paper_list = [[0 for i in range(100)] for j in range(100)] times = int(input()) for _ in range(times): x, y = map(int, input().split()) for row in range(x, x+10): for col in range(y, y+10): paper_list[row][col] = 1 result ..
ยทpython
https://www.acmicpc.net/problem/10789 10789๋ฒˆ: ๊ฐ€์ƒ ํ‚ค๋ณด๋“œ ์ž…๋ ฅ ์ž…๋ ฅ์˜ ์ฒซ ๋ฒˆ์งธ ์ค„(ํ–‰)์—๋Š” ๋‘ ๊ฐœ์˜ ์ •์ˆ˜ r๊ณผ c (1 ≤ r, c ≤ 50)๊ฐ€ ํฌํ•จ๋˜์–ด ๊ฐ€์ƒ ํ‚ค๋ณด๋“œ ๊ฒฉ์ž์˜ ํ–‰๊ณผ ์—ด ์ˆ˜๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๊ฐ€์ƒ ํ‚ค๋ณด๋“œ๋Š” ๋‹ค์Œ r ํ–‰์— ํ‘œ์‹œ๋˜๋ฉฐ ๊ฐ ํ–‰์—๋Š” c ๋ฌธ์ž๊ฐ€ ๋“ค์–ด ์žˆ์Šต๋‹ˆ๋‹ค. www.acmicpc.net ์ฝ”๋“œ my_list = [] for _ in range(5): my_list.append(list(input())) for row in range(15): for col in range(5): try: print(my_list[col][row], end="") except: continue ์„ค๋ช… 1. my_list์— ์ž…๋ ฅ๊ฐ’์„ ํ•œ์ค„ ์”ฉ list๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์ €์žฅํ•œ๋‹ค. (2..
Chan Lee
'python' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก