1.정수를 입력하고, 입력한 숫자만큼 hello 출력
count = int(input("정수 : "))
if count <= 0:
print("다시 시도하세요")
else:
n = 0
while n != count:
print("%d번째 Hello" %(n+1))
n += 1

2. 7의 배수 구하기
n = 0
while n < 98:
n += 7
print(n)

3. 커피는300원일때 가진 돈을 입력받고 커피를 몇 잔 먹을 수있는지와 잔돈을 계산하시오
coffee = 0
money = int(input("금액을 넣어주세요 >>>"))
while money >= 300:
coffee += 1
money -= 300
print("커피 {}잔. 잔돈 {}원".format(coffee, money))

4. 중복 없이 0~9사이의 정수를 받으시오
numSet = set()
num = 0
while len(numSet) < 5 :
num = int(input("0~9사이의 정수 : "))
numSet.add(num)
print("모두 입력되었습니다.")0
print("입력된 값은 {}입니다.".format(numSet))

5. 1~100 사이 모든 정수를 한 줄에 10개씩 출력
n = 1
while n <= 100:
if n % 10 == 0:
print(n)
else:
print(n, end="\t")
n += 1

6. 구구단
n = 1
dan = 2
while n <= 9:
dan = 2
while dan <= 9:
print("%d*%d=%d" %(dan, n, dan*n), end="\t")
dan += 1
print()
n += 1

7. 1~5사이의 정수를 역순으로 출력
for i in range(5):
print(5-i)

8. 임의의 정수를 입력받고, 1~입력받은 정수까지의 합을 구하라
sumTo = int(input("양의 정수 : "))
result = 0
for i in range(sumTo):
result += i + 1
print(result)

9. 임의의 양의정수를 입력받고, 그만큼의 과일을 보관하시오
cnt = int(input("몇 개의 과일을 보관할까요?"))
fruitList = []
for i in range(cnt):
fruitList.append(input("%d번째 과일을 입력하세요 >>> " %(i+1)))
print(fruitList)

10. 100점을 제외한 점수에 +5 점을 하고 출력하시오. 단, 100점을 넘으면 안됨
exam = [99, 78, 100, 91, 81, 85, 54, 100, 71, 50]
#min(값, 최소값): 값은 최소값을 지켜야 한다.
score = [min(n + 5, 100) for n in exam]
print(score)

11. 369게임
for n in range(1, 100):
units = n % 10
tens = n // 10
c1 = units % 3 == 0 and units != 0
c2 = tens % 3 == 0 and tens != 0
if c1 and c2 :
print('짝짝', end="\t")
elif c1 or c2:
print('짝', end="\t")
else:
print(n, end="\t")
if n % 10 == 0:
print()

댓글남기기