Computer Science/Jongol (정올)

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

꿈꾸는어린이 2018. 1. 14. 20:08

//

일시 : 2018.01.04

내용 : Jongol 반복제어문2

//

hw 소수 프로그램

  num = input("# 양수 입력 : ")
num = int(num)
flag, count = 0, 0
str = ''

for i in range(2, num+1):
if i == 2 :
str += ("%3d " % i)
count += 1

else :
for j in range(2, i):
if i % j == 0 :
flag = 1
break
flag = 0

if flag == 0 :
count += 1
if count % 5 == 0:
str += ("%3d \n" % i)
else :
str += ("%3d " % i)

print(str)


129 ※

  
base, height, width = 0, 0, 0.0
ch = ''

base = int(input("Base = "))
height = int(input("Height = "))
width = float(base*height) / 2
print("Triangle width = %.1f" % width)
ch = input("Continue? ")

while True :
if (ch == 'y') or (ch == 'Y') :
base = int(input("Base = "))
height = int(input("Height = "))
width = float(base*height) / 2
print("Triangle width = %.1f" % width)
ch = input("Continue? ")
else :
break


548

  
str=''

for i in range(2, 5):
for j in range(1, 6):
str += ("%d * %d = %2d   " % (i, j, (i*j)))
str += "\n"

print(str)


134

  
even, odd, num = 0, 0, 0

numStr = raw_input()
numList = numStr.split()

for i in range(0, 10):
num = int(numList[i])

if num % 2 == 0:
even += 1
else :
odd += 1

print("even : %d" % even)
print("odd : %d" % odd)


135

  
a, b = raw_input().split()
a = int(a)
b = int(b)
count, sum, avg = 0, 0, 0.0

if a < b :
for i in range(a, b+1):
if (i % 3 == 0) or (i % 5 == 0):
sum += i
count += 1
else :
for i in range(b, a+1):
if (i % 3 == 0) or (i % 5 == 0):
sum += i
count += 1

avg = float(sum) / count

print("sum : %d" % sum)
print("avg : %.1f" % avg)


136

  
a = int(input())

for i in range(1, 11):
print(a*i),


137

  
row, col = raw_input().split()

row = int(row)
col = int(col)

n = 1

for i in range(1, row+1):
for j in range(1, col+1):
print(i*j),
print("")