(3) 튜플(tuple)
특성:
* 인덱싱(indexing)
* 스라이싱(slicing)
* 연결 연산자(+)
* 반복 연산자(*)
* 요소의 변경 X
* 중복된 요소 가능
함수:
* count() - 요소의 개수
* index() - 요소의 index
(4) 딕셔너리(dictionary)
특성:
* 인덱싱(indexing) X
* 스라이싱(slicing) X
* 연결 연산자(+) X
* 반복 연산자(*) X
* 요소의 변경 0
* 중복된 요소 가능 X
함수:
* keys(), values(), items()
* update(), dict1['k']='v'
* get()
(5) 집합(set)
특성:
* 인덱싱(indexing) X
* 스라이싱(slicing) X
* 연결 연산자(+) X
* 반복 연산자(*) X
* 요소의 변경 0
* 중복된 요소 가능 X
함수:
* add(), remove()
* update()
* 교집합: set1 & set2
* 합집합: set1 | set2
* 차집합: set1 - set2
제 03 장 연산자
산술 연산자(+ - * / // %)
비교 연산자(== != > < >= <=)
할당 연산자(+= -=)
논리 연산자(and, or, not)
구성원 연산자(in, not in)
식별 연산자(is, is not)
제 04 장 제어 구문
(1) 조건 구문(if)
if 조건1:
실행1
elif 조건2:
실행2
else:
실행3
(2) 반복 구문(for, while)
for var in var_list:
실행
while True:
실행
반복구문 제어
continue
break
M = ['짜장', '짬뽕', '우동', '울면']
B = ['짜밥', '짬밥', '볶밥']
S = [['탕','짜','짜'], ['탕','잡','물']]
M.append('간짜')
M.remove('우동')
M.insert(M.index('울면'), '사짜')
print(M)
print(len(M) + len(B))
summenu = M + B
print(summenu)
summenu.sort(reverse=True)
print(summenu)
S.append(['탕슉', '고잡', '짬뽕'])
print(S)
===============================================
movie = {'염력': [23.6, 5.5],
'그것만이':[20.6, 8.8],
'코코': [15.6, 8.8]}
numbers = [1,2,3,4,5,6,7]
print("min: ", min(numbers))
print("max: ", max(numbers))
print("average: ", sum(numbers) / len(numbers))
=================================================
data = ['a', 'b', 'c', 'd']
print(tuple(data))
print(''.join(data))
=================================================
numbers = [1, 2, 3, 4, 5, 3, 2, 9, 10, 3]
numbers.remove(3)
print(numbers)
del numbers[4]
del numbers[-1]
print(numbers)
====================================================
중요!
[문제] 암호학
● 'A' + 3 => 'D', 'B' + 3 => 'E', 'X' + 3 => 'A', 'Y' + 3 => 'B', 'Z' + 3 => 'C'
● (input)ABCDEFGHIJKLMNOPQRSTUVWXYZ => (output)DEFGHIJKLMNOPQRSTUVWXYZABC
plaintext = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ciphertext = []
for i in range(len(plaintext)):
#print(i, end=' ')
index = (i + 3) % len(plaintext)
ciphertext.append(plaintext[index])
print(''.join(ciphertext))
출력값 : DEFGHIJKLMNOPQRSTUVWXYZABC
=====================================================
함수
def magu(x, y, *rest):
print(x, y, rest[3:])
magu(1, 2, 3, 4 ,5 ,6, 7)
def magu(x, y, *rest):
return x, y
a, b = magu(1, 2)
print(a,b)
출력: 1 2
def magu(x, y, *rest):
return x, y
result = magu(1, 2)
print(result)
출력 : (1, 2)
===============================================
딕셔너리
a = {'name': 'Lee', 'phone': '01031313131', 'birth': '1029'}
for k, v in a.items():
print(k, v)
if v == 'Lee':
print(k)
print([k for k,v in a.items() if v == 'Lee'])
a['phone'] = '0113033030'
print(a)
a.update({'gender':'man', 'name': 'Super'})
print(a)
=====================================================
a = {'one':1, 'two':2, 'three':3, 'four':4, 'five':4}
for i in a.items():
if i[1] == 4:
print(i[0])
=====================================================
Ice= {'melona': [100, 10],
'pollapo': [1200, 7],
'ppang': [1800, 6],
'tank' : [1200, 5],
'heat' : [1200, 4],
'world' : [1500, 3]}
for iname, irest in Ice.items() :
if irest[1] == 7:
print(iname)
print([iname for iname, irest in Ice.items() if irest[1] ==7])
============================================================
set
list1 = [1,2,3,1,3]
print(list1)
print(set(list1))
print(list(set(list1)))
=====================================================
s1 = {1, 2, 3, 4, 5, 6}
s2 = {4, 5, 6, 7, 8, 9}
print(s1 & s2)
print(s1 | s2)
print(s1 - s2)
======================================================
filenames = ['intra.h', 'intra.c', 'input.txt', 'run.py']
results=[]
for i in filenames :
ext = i.split('.')
#print(ext[1])
if ext[1] == 'h' or ext[1] == 'c':
#print(i)
results.append(i)
print(results)
=========================================================
num1 = input("input num1 :")
num2 = input("input num2 :")
n1 = int(num1)
n2 = int(num2)
if n1 >= n2:
result_n = n1
else:
result_n = n2
print(result_n)
if result_n % 2 == 0:
print('Even Number')
else:
print('Odd Number')
=========================================
score = int(input('score : '))
cmp_score = int(score)
if 81 <= cmp_score <= 100:
result_grade = 'A'
elif 61 <= cmp_score <= 80:
result_grade = 'B'
elif 41 <= cmp_score <= 60:
result_grade = 'C'
else:
result_grade = 'D'
print("grade is ", result_grade)
=====================================================
a = input('주민번호입력: ')
if a.split('-')[1][0] == '1' :
print("성별: 남성")
elif a.split('-')[1][0] == '2' :
print("성별: 여성")
if a.split('-')[1][1:2] <= '08':
print("출생지: 서울")
elif int(a.split('-')[1][1:2]) <= 12 :
print("출생지: 부산")
else:
print("외국인")
==========================================================
marks = [90, 25, 67, 33, 76]
count = 1
for mark in marks:
if mark >= 60 :
print('%d 번째 학생 합격' % count)
else:
print('%d 번째 학생 불합격' % count)
count +=1
number = 0
for mark in marks:
number += 1
if mark < 60: continue
print("%d 번 학생: 합격" % number)
=======================================
prompt = """
1. add
2. del
3. list
4. quit
"""
while True:
print(prompt)
num = input("Enter number (1/2/3/4) : ")
if int(num) == 4:
break
import sys
coffee_num = 5
while True:
if not coffee_num :
sys.exit("Error: 품절 ")
income = input("돈을 넣으세요 : ")
int_money = int(income)
if int_money > 300 :
print("커피 1개가 나옵니다")
remainder = int_money - 300
print("거스름 돈 받아라! %d" % remainder)
coffee_num -=1
elif int_money == 300 :
print('커피 1개 받아라')
coffee_num -=1
elif 0 < int_money < 300 :
print('돈 더 넣어라 %d' %int_money)
else :
sys.exit("Error: Unknown Error")
print("남은 커피 갯수 %d" % coffee_num)
[커피 자판기 과제]
커피 갯수를 주문 받는다.
주문 받은 커피의 금액을 말해준다.
돈을 받는다.
부족하면 더 달라고 하고 많으면 거스름돈 돌려준다.
준비된 재고의 갯수를 알려준다.
import sys
avail_coffee = 50
coffee = 300
while True:
if not avail_coffee :
sys.exit("품절! 재고 준비중입니다")
coffee_num = int(input("커피 몇 개를 드릴까요 : "))
if coffee_num > avail_coffee :
print("수량이 부족합니다. %d개까지 구입 가능합니다." %avail_coffee) ; print()
continue
else :
price = coffee_num * coffee
print("금액은 %d 원 입니다." %price) ; print()
ask = int(input("금액을 넣어주세요 : "))
if ask < price :
print("%d원이 부족합니다." % (price - ask)) ; print()
continue
elif ask > price :
avail_coffee -= coffee_num
print("%d원을 받았습니다.\n\n[+] 커피 %d개가 나왔습니다.\n거스름돈은 %d원 입니다.\n" %(ask, coffee_num, price-ask))
print ("[*] 커피 재고 %d개" % avail_coffee) ; print()
elif ask == price :
avail_coffee -= coffee_num
print("커피 %d개가 나왔습니다. 감사합니다.\n[*] 커피 재고 %d개" %(coffee_num, avail_coffee)) ; print()
'정보보안공부 > 정보보안전문과정' 카테고리의 다른 글
정보보안 과정 Day 75 : Python4 (0) | 2020.12.22 |
---|---|
정보보안 과정 Day 74 : Python 3 (0) | 2020.12.21 |
정보보안 과정 Day72 : Python 시작 (0) | 2020.12.17 |
정보보안 과정 DAY 69~71 : 리버싱 문제 풀기 (0) | 2020.12.17 |
정보보안 과정 Day 68 : 리버싱 6 (FSB / BOF) (0) | 2020.12.14 |