Computer Science/Jongol (정올)

[Jongol] 기초다지기 : 반복제어문3

꿈꾸는어린이 2018. 2. 3. 14:33

//

일시 : 2018.01.29 동주랑 카페,

2018.02.03 동주랑 답십리 도서관

내용 : 정올 기초다지기-반복제어문3 (파이썬2버전)

//

138

  n = int(raw_input())

for i in range(1, n+1):
for j in range(1, n+1):
print("(%d, %d)" % (i, j)),
print("")

139

  
a, b = raw_input().split()
a = int(a)
b = int(b)

if a > b:
for i in range(1, 10):
for j in range(a, b-1, -1):
print("%d * %d = %2d   " % (j, i, (j*i))),
print("")
else:
for i in range(1, 10):
for j in range(a, b+1, 1):
print("%d * %d = %2d   " % (j, i, (j*i))),
print("")

549

  
n = int(raw_input())

result = 0
count = 0
i = 1

while True:
if result >= n:
break
result += i
count += 1
i += 2

print("%d %d" % (count, result))

634

  
n = int(raw_input())

for i in range(1, n+1):
str = ""
for j in range(i):
str += "*"
print(str)

550

  
n = int(raw_input())

for i in range(n, 0, -1):
str = ""
for j in range(i):
str += "*"
print(str)
for i in range(1, n+1):
str = ""
for j in range(i):
str += "*"
print(str)

551

  
n = int(raw_input())

for i in range(n, 0, -1):
str = ""
for j in range(n-i):
str += " "
for j in range(i):
str += "*"
print(str)

552

  
n = int(raw_input())

##1+2d
cnt = 1+2*(n-1)

for i in range(0, n):
str = ""
for j in range(i):
str += " "
for k in range(cnt - (2*i)):
str += "*"
for j in range(i):
str += " "
print(str)

553

  
n = int(raw_input())
ch = 'A'

for i in range(n, 0, -1):
str = ""
for j in range(i):
str += ch
ch2 = ord(ch)+1
ch = chr(ch2)
print(str)

554

  
n = int(raw_input())
digit = 1
alpha = 'A'

for i in range(n):
for j in range(n-i, 0, -1):
print(digit),
digit += 1
for k in range(i+1):
print(alpha),
ch2 = ord(alpha)+1
alpha = chr(ch2)
print("")

140

  
num = raw_input().split()

i, sum = 0, 0

while i < 20:
if int(num[i]) == 0:
break

sum += int(num[i])
i += 1

avg = sum / i
print("%d %d" % (sum, avg))

141

  
num = int(raw_input())
i = 1

while True:
if (num*i) > 100 :
break

print("%d" % (num*i)),

if ((num*i) % 10 == 0):
break
i += 1

142

  
num = int(raw_input())
i = 1

while i <= num:
str = ""
for j in range(i):
str += "*"
print(str)
i += 1

i = num - 1
while i > 0:
str = ""
for j in range(i):
str += "*"
print(str)
i -= 1

143

  
num = int(raw_input())

#1 + 2i / i = num-1

for i in range(num, 0, -1):
cnt = 1 + 2*(i-1)
str = ""
for j in range(num-i):
str += " "
for j in range(cnt):
str += "*"
for j in range(num-i):
str += " "
print(str)

for i in range(2, num+1):
cnt = 1 + 2*(i-1)
str = ""
for j in range(num-i):
str += " "
for j in range(cnt):
str += "*"
for j in range(num-i):
str += " "
print(str)

144

  
num = int(raw_input())

total = 1 + 2*(num-1)
i = 1

while i <= num:
str = ""
a = 1 + 2*(i-1)
for j in range(total - a):
str += " "
for j in range(a):
str += "*"
print(str)
i += 1

145

  
num = int(raw_input())

for i in range(1, num+1):
for j in range(num-i):
print(" "),
for k in range(1, i+1):
print("%d" % k),
print("")

146

  
num = int(raw_input())

ch = 'A'
digit = 0
for i in range(0, num):
for j in range(num-i):
print("%c" % ch),
temp = ord(ch) + 1
ch = chr(temp)
for j in range(i):
print("%d" % digit),
digit += 1
print("")

147

  
num = int(raw_input())

digit = 1

for i in range(0, num+1):
for j in range(i):
print(" "),
for j in range(num-i):
print("%d" % digit),
digit += 1
print("")

148

  num = int(raw_input())

for i in range(1, num+1):
for j in range(i):
print("#"),
for j in range(num-i):
print(" "),
print("")

for i in range(1, num):
for j in range(i):
print(" "),
for j in range(num-i):
print("#"),
print("")

149

  num = int(raw_input())
digit = 1

for i in range(num):
for j in range(num):
if digit > 10:
digit = 1
print("%d" % digit),
digit += 2
print("")