일시 : 2018.01.03 13:00pm ~ 17:00pm
내용 : Jongol 반복제어문 133번까지
★은 실패했던 문제, ※은 미해결 문제
//
536 : 반복제어문1 - 자가진단1
i = 1
str = ''
while i <= 15 :
str += ("%d " % i)
i+=1
print(str)
537
num = int(input())
i,sum = 1, 0
while i <= num :
sum = sum + i
i = i + 1
print(sum)
538
num = int(input("number? "))
while True :
if num > 0 :
print("positive integer")
elif num < 0 :
print("negative number")
else :
break
num = int(input("number? "))
539 ★★★
sum, avg, var_str, var_list = 0, 0.0, "", []
i = 0
var_str = raw_input()
var_list = var_str.split()
while True :
sum = sum + int(var_list[i])
i = i + 1
if int(var_list[i-1]) >= 100 :
break
print("%d" % sum)
avg = float(sum) / i
print("%.1f" % avg)
540
while True :
num = int(raw_input())
if (num % 3 == 0):
print(num // 3)
if num == -1:
break
633
while True :
num = int(input("1. Korea\n2. USA\n3. Japan\n4. China\nnumber?"))
if num == 1:
print("\nSeoul\n")
elif num == 2 :
print("\nWashington\n")
elif num == 3 :
print("\nTokyo\n")
elif num == 4 :
print("\nBeijing\n")
else :
print("\nnone\n")
break
125
num = int(input())
str =''
for i in range(1, num+1):
str+= ("%d " % i)
print(str)
126
numStr = raw_input()
numList = numStr.split()
odd_count, even_count, i, num = 0, 0, 0, 0
while True :
num = int(numList[i])
if num == 0 :
print("odd : %d" % odd_count)
print("even : %d" % even_count)
break
if (num % 2) != 0 :
odd_count += 1
elif (num % 2) == 0 :
even_count += 1
i+=1
127
scoreStr = raw_input()
scoreList = scoreStr.split()
sum, avg, i = 0, 0.0, 0
while True :
if (int(scoreList[i]) >= 0) and (int(scoreList[i]) <= 100):
sum += int(scoreList[i])
i+=1
else :
print("sum : %d" % sum)
print("avg : %.1f" % (float(sum) / i))
break
128
var_str = raw_input()
var_list = var_str.split()
i, count = 0, 0
while True :
num = int(var_list[i])
if num == 0 :
print(count)
break
if (num % 3 == 0) or (num % 5 == 0) :
i += 1
continue
i += 1
count += 1
129 ※※
base = int(input("Base = "))
height = int(input("Height = "))
width = (float(base) * float(height)) / 2
print("Triangle width = %.1f" % width)
con = raw_input("Continue? ")
while con == 'Y' :
base = int(input("Base = "))
height = int(input("Height = "))
width = float(base * height) / 2
print("Triangle width = %.1f" % width)
con = raw_input("Continue? ")
if con == 'N' :
break
541 : 반복제어문2 ※
import sys
var_str = raw_input()
v = var_str[0]
542
str = ''
for i in range (10, 21):
str += ("%d " % i)
print(str)
543
num = int(input())
str = ''
for i in range(1, num+1) :
if i % 2 == 0 :
str += ("%d " % i)
else:
continue
print(str)
544
num = int(input())
sum = 0
for i in range(num, 101) :
sum += i
print(sum)
545
i = 0
mul3, mul5 = 0, 0
var_str = raw_input()
var_list = var_str.split()
for i in range (10) :
if int(var_list[i]) % 3 == 0 :
mul3 += 1
if int(var_list[i]) % 5 == 0 :
mul5 += 1
print("Multiples of 3 : %d" % mul3)
print("Multiples of 5 : %d" % mul5)
546
num = int(input())
var_str = raw_input()
var_list = var_str.split()
sum, avg= 0, 0.0
for i in range(0, num):
sum += int(var_list[i])
avg = float(sum) / num
print("avg : %.1f" % avg)
if avg >= 80.0:
print("pass")
else:
print("fail")
547
줄바꿈 방지
python 3 버전 => end=" "
python 2 버전 => 끝에 ,(콤마) print(j),
for i in range (1, 6) :
for j in range (i+1, i+6) :
print(j),
print("")
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)
130
num = int(input())
for i in range(num):
print("JUNGOL")
131
a, b = raw_input().split()
a = int(a)
b = int(b)
if a > b :
for i in range(b, a+1):
print(i),
else :
for i in range(a, b+1):
print(i),
132
a = int(input())
sum, i = 0, 0
for i in range(i, a+1):
if i % 5 == 0 :
sum += i
print(sum)
133
num = int(input())
sum = 0
var_str = raw_input()
for i in range(0, num):
var_list = var_str.split()
sum += int(var_list[i])
avg = float(sum) / num
print("%.2f" % avg)
'Computer Science > Jongol (정올)' 카테고리의 다른 글
[Jongol] 기초다지기 : 반복제어문3 (0) | 2018.02.03 |
---|---|
[Jongol] 기초다지기 : 반복제어문2 (0) | 2018.01.14 |
[Jongol] 기초다지기 : 선택제어문 (0) | 2018.01.02 |
[Jongol] 기초다지기 : 연산자부터 디버깅까지 (0) | 2018.01.02 |
[Jongol] 기초다지기 - 연산자 (1) | 2018.01.02 |