Python - 복습 겸 연습문제 풀기
by jennysgap복습 겸 연습문제 풀기
1
num = 0 while num <= 100 : print(num, end=' ') num += 1
2
num = 1 while num <= 100 : print(num, end=' ') num += 1
3
num = 100 while num <= 200 : print(num, end=' ') num += 1
4
n = int(input('입력(n):')) num = 0 while num <= n : print(num, end=' ') num += 1
5
s = int(input('입력(s): ')) e = int(input('입력(e): ')) while s <= e : print(s, end=' ') s += 1
6
num = 0 while num <= 100 : if num % 2 != 0 : print(num, end=' ') num += 1
7
num = 0 while num <= 100 : if num == 0 : pass elif num % 2 == 0 : print(num, end=' ') num += 1
8
num = 0 while num <= 100 : if num == 0 : pass elif num % 7 == 0 : print(num, end=' ') num += 1 num += 1
9
num = 0 while num <= 100 : num += 1 if num % 13 == 0 : print(num, end=' ')
10
num = 0 while num <= 100 : num += 1 if num % 5 == 0 and num % 7 == 0 : print(num, end=' ')
11
s = int(input('입력(s): ')) e = int(input('입력(e): ')) while s <= e : if s % 2 != 0 : print(s, end=' ') s += 1 s += 1
12
s = int(input('입력(s): ')) e = int(input('입력(e): ')) while s <= e : if s == 0 : pass elif s % 2 == 0 : print(s, end=' ') s += 1 s += 1
13
s = int(input('입력(s): ')) e = int(input('입력(e): ')) while s <= e: if s == 0: pass elif s % 5 == 0 and s % 7 == 0: print(s, end=' ') s += 1 s += 1
14
num = 100 while num >= 0 : print(num, end=' ') num -= 1
15
s = int(input('입력(s): ')) e = int(input('입력(e): ')) while e >= s : print(e, end=' ') e -= 1
16
mylist = [56, 63, 33, 42, 16, 88, 45, 42, 35, 58] num = 0
# 방법1 newlist = [] while num <= 9 : newlist.append(mylist[num] * 2) num += 1 print(newlist) # 방법2 ''' newlist = mylist.copy() # 리스트copy하여 새로만들기
# newlist = mylist[:] while num <= 9 : newlist[num] = newlist[num] * 2 num += 1 print(newlist)
'''
17
mylist = [56, 63, 33, 42, 16, 88, 45, 42, 35, 58] newlist = [] for num in mylist : if num % 2 != 0 : newlist.append(num+1) else : newlist.append(num) print(newlist)
18
mylist = [56, 63, 33, 42, 16, 88, 45, 42, 35, 58] cnt = 0 for num in mylist : mylist[cnt] = '{:x}'.format(num) cnt += 1 print(mylist)
19
mylist = [] cnt = 0 while cnt < 10 : cnt += 1 num = int(input('{}번째 정수를 입력해 주세요: '.format(cnt))) mylist.append(num) print(mylist)
20
mylist = [56, 63, 33, 42, 16, 88, 45, 42, 35, 58] sum = 0 for num in mylist : sum += num age = sum / 10 mytuple = (sum, age) print(mytuple)
21
# 방법1 str = input('입력:') enter = '\n' print(enter.join(str)) # 방법2 ''' msg = input('입력:') msglen = len(msg) cnt = 0 while cnt < msglen : print(msg[cnt]) cnt += 1 '''
22
num = input('입력:') numlen = len(num) cnt = 0 while cnt < numlen : if int(num[cnt]) % 2 == 0 : print('{} : 짝수'.format(num[cnt])) cnt += 1 else : print('{} : 홀수'.format(num[cnt])) cnt += 1
'BOX' 카테고리의 다른 글
Python - 14.함수 (0) | 2017.02.03 |
---|---|
안랩 보안 바로알기 캠페인 (0) | 2017.02.03 |
Python - 13.WHILE과 FOR (0) | 2017.02.01 |
Python - 12.IF문 (0) | 2017.01.31 |
안랩 정보 수집 중.. (구 자료) (0) | 2017.01.31 |
블로그의 정보
jennysgap
jennysgap