ProgrammingLogic문제 [yong27]의 [Python]버젼 1) 가장기본적인... {{{ @@@@@@@ @@@@@@ @@@@@ @@@@ @@@ @@ @ }}} {{{#!python def ProOne(): for i in range(7,0,-1): print '@'*i }}} 2) 인덱스를 두개(i,j)를 돌린다는게 좀 맘에걸림 {{{ @@@@@@@ @@@@@ @@@ @ }}} {{{#!python def ProTwo(): j=0 for i in range(7,0,-1): if i%2 == 1: print ' '*j+'@'*i j+=1 }}} ---- {{{ >>> for linei in range(4): stars=7-linei*2 print ' '*linei+'*'*stars }}} --[김창준] ---- 3) 첫째줄을 같이 쓸수 있는 로직이 있을까 고민했으나 못찾음 {{{ @@@@@@@ @@ @ @ @ @ @ @ @ @ @ @ }}} {{{#!python def ProThree(): for i in range(7): if i==0: print '@'*7 else: print '@'+' '*(i-1)+'@' }}} ---- {{{ >>> for i in range((7+1)*7): row,col=divmod(i,8) if col>=7: c='\n' else: c= (not row or not col or row==col) and '*' or ' ' sys.stdout.write(c) }}} --[김창준] ---- and then now a more general approach is possible: {{{ def printCells(aRow,aCol,aIsStar): for i in range((aCol+1)*aRow): row,col=divmod(i,aCol+1) if col>=aCol: c='\n' else: c= aIsStar(row,col) and '*' or ' ' sys.stdout.write(c) >>> printCells(7,7,lambda row,col:-col+6>=row) >>> printCells(4,7,lambda row,col:((col-3)+3 >= row and (3-col)+3 >= row )) >>> printCells(7,7,lambda row,col:not row or not col or row==col) }}} I would call this a paradigm(esp. a Cartesian) of programming, which is a way of solving a category of similar problems, as in Seminar:TheParadigmsOfProgramming. --[김창준]