# end 파라미터 사용
print("Hello", end=" ")
print("World")
# 출력: Hello World
print("One", end=", ")
print("Two", end=", ")
print("Three")
# 출력: One, Two, Three
-----------------------
# sep 파라미터 사용
print("Hello", "World", sep="-") # 출력: Hello-World
print("2024", "10", "10", sep="/") # 출력: 2024/10/10
print("Python", "Java", "C++", sep=" | ") # 출력: Python | Java | C++
-----------------------
# sep와 end 함께 사용
print("Python", "is", "awesome", sep="-", end="!")
# 출력: Python-is-awesome!
-----------------------
# strip, lstrip, rstrip - 공백 제거
text = " Hello, World! "
print(text.strip()) # "Hello, World!"
print(text.lstrip()) # "Hello, World! "
print(text.rstrip()) # " Hello, World!"
# capitalize - 첫 글자를 대문자로
text = "hello"
print(text.capitalize()) # "Hello"
# endswith, startswith - 문자열 끝/시작 확인
file_name = "보고서.xlsx"
print(file_name.endswith("xlsx")) # True
print(file_name.startswith("보고서")) # True
# 리스트 - 변경 가능
my_list = [1, "apple", 3.14, True]
my_list.append("banana")
print(my_list) # [1, "apple", 3.14, True, "banana"]
# 배열 - array 모듈 사용
import array
my_array = array.array('i', [1, 2, 3, 4])
my_array.append(5)
print(my_array) # array('i', [1, 2, 3, 4, 5])
# NumPy 배열
import numpy as np
# 1차원 배열
my_numpy_array = np.array([1, 2, 3, 4])
my_numpy_array = my_numpy_array + 1
print(my_numpy_array) # [2 3 4 5]
# 2차원 배열
my_2d_array = np.array([[1, 2], [3, 4]])
print(my_2d_array) # [[1 2]
# [3 4]]
# 튜플 - 변경 불가능
my_tuple = (1, 2, 3)
print(my_tuple) # (1, 2, 3)
# 딕셔너리 - 키-값 형태
my_dict = {"apple": 1, "banana": 2}
print(my_dict) # {"apple": 1, "banana": 2}
# 리스트 생성 및 요소 추가
movie_rank = ["닥터 스트레인지", "스플릿", "럭키"]
movie_rank.append("배트맨")
print(movie_rank)
# 리스트에 요소 삽입
movie_rank = ['닥터 스트레인지', '스플릿', '럭키']
movie_rank.insert(1, "슈퍼맨")
print(movie_rank)
# 리스트에서 요소 삭제
movie_rank = ['닥터 스트레인지', '슈퍼맨', '스플릿', '럭키', '배트맨']
del movie_rank[3]
print(movie_rank)
# 리스트 연결
lang1 = ["C", "C++", "JAVA"]
lang2 = ["Python", "Go", "C#"]
langs = lang1 + lang2
print(langs)
# 리스트의 최대값과 최소값 출력
nums = [1,2,3,4,5,6,7]
print("max: ", max(nums))
print("min: ", min(nums))
# 리스트 요소의 합 계산
nums = [1,2,3,4,5]
print(sum(nums))
# 리스트의 길이 계산
cook = ["피자", "김밥", "만두", "양념치킨", "족발", "피자", "김치만두", "쫄면", "소시지", "라면", "팥빙수", "김치전"]
print(len(cook))
# 리스트 요소의 평균 계산
nums = [1,2,3,4,5]
average = sum(nums) / len(nums)
print(average)
# 삼성전자 LG전자 Naver SK하이닉스 미래에셋대우 // 형태로 출력
interest = ['삼성전자', 'LG전자', 'Naver', 'SK하이닉스', '미래에셋대우']
print(" ".join(interest))
# 삼성전자/LG전자/Naver/SK하이닉스/미래에셋대우 // 형태로 출력
interest = ['삼성전자', 'LG전자', 'Naver', 'SK하이닉스', '미래에셋대우']
print("/".join(interest))
# 삼성전자
# lG전자 // 형태로 출력
interest = ['삼성전자', 'LG전자', 'Naver', 'SK하이닉스', '미래에셋대우']
print("\\n".join(interest))
# ['삼성전자', 'LG전자', 'Naver']
string = "삼성전자/LG전자/Naver"
a = string.split("/")
print(a)
# [1, 2, 3, 4, 5, 9, 10]
data = [2,4,3,1,5,10,9]
data.sort()
print(data)
# int
my_utple = (1)
print(type(my_utple))
# tuple
my_utple = (1, )
print(type(my_utple))
# (2, 4, 6, 8 ~ 98)
data = tuple(range(2, 100, 2))
print( data )
# [8.8, 8.9, 8.7, 9.2, 9.3, 9.7, 9.9]
scores = [8.8, 8.9, 8.7, 9.2, 9.3, 9.7, 9.9, 9.5, 7.8, 9.4]
*valid_score, _, _, _=scores
print(valid_score)
# [8.7, 9.2, 9.3, 9.7, 9.9, 9.5, 7.8, 9.4]
scores = [8.8, 8.9, 8.7, 9.2, 9.3, 9.7, 9.9, 9.5, 7.8, 9.4]
a, b, *valid_score = scores
print(valid_score)
# 딕셔너리 값 추가
ice = {"메로나" : 1000, "폴라포" : 1200, "빵빠레" : 1800}
ice["죠스바"] = 1200
print(ice)
# 메로나 가격 출력
ice = {'메로나': 1000,
'폴로포': 1200,
'빵빠레': 1800,
'죠스바': 1200,
'월드콘': 1500}
print("메로나 가격: ", ice["메로나"])
# 값 변경
ice = {'메로나': 1000,
'폴로포': 1200,
'빵빠레': 1800,
'죠스바': 1200,
'월드콘': 1500}
ice['메로나'] = 1300
print(ice)
# 삭제
ice = {'메로나': 1000,
'폴로포': 1200,
'빵빠레': 1800,
'죠스바': 1200,
'월드콘': 1500}
del ice['메로나']
print(ice)
# 딕셔너리 값 여러 개
inventory = {'메로나' : [300, 20],
'비비빅' : [400, 3],
'죠스바' : [250, 100]}
print(inventory)
# 값 가져오기
inventory = {'메로나' : [300, 20],
'비비빅' : [400, 3],
'죠스바' : [250, 100]}
print(inventory['메로나'][1],"개")
# 값 추가
inventory = {'메로나' : [300, 20],
'비비빅' : [400, 3],
'죠스바' : [250, 100]}
inventory['월드콘'] = [500,7]
print(inventory)
# 키, 값 따로 출력
icecream = {'탱크보이': 1200, '폴라포': 1200, '빵빠레': 1800, '월드콘': 1500, '메로나': 1000}
ice = list(icecream.keys())
ice2 = list(icecream.values())
print(ice)
print(ice2)
# 값 모두 더하기
icecream = {'탱크보이': 1200, '폴라포': 1200, '빵빠레': 1800, '월드콘': 1500, '메로나': 1000}
ice2 = sum(icecream.values())
print(ice2)
# 딕션너리 합치기
icecream = {'탱크보이': 1200, '폴라포': 1200, '빵빠레': 1800, '월드콘': 1500, '메로나': 1000}
new_product = {'팥빙수' : 2700, '아맛나' : 1000}
icecream.update(new_product)
print(icecream)
# zip - 두 데이터를 엮어줌
# 리스트 2개를 zip으로 묶은 뒤 dict로 생성
keys = ("apple", "pear", "peach")
vals = (300,250,400)
result = dict(zip(keys, vals))
print(result)
# 홀짝 구분
user = input()
if int(user) % 2 == 0:
print("짝수")
else:
print("홀수")
# input 값을 받아 리스트에 포함되어 있는지
fruit = ["사과", "포도", "홍시"]
user = input()
if user in fruit:
print("정답")
else:
print("오답")
# 딕셔너리에서 value값으로 판단
data = {"봄" : "딸기", "여름" : "토마토", "가을" : "사과"}
user = input()
if user in data.values():
print("정답")
else:
print("오답")
# socre별로 학점
socre = int(input())
if socre >= 81:
print("A")
elif 80 >= socre >= 61:
print("B")
elif 60 >= socre >= 41:
print("C")
elif 40 >= socre >= 20:
print("D")
else:
print("E")
# 나라별 화페 환율 계산
환율 = {"달러": 1167,
"엔": 10.96,
"유로": 1268,
"위안": 171}
user = input("입력: ")
num, currency = user.split() // 100 달러 입력 시 num=100, currency=달러 값을 가짐,
그리고 currency에 해당하는 key값의 value를 가져옴
print(float(num) * 환율[currency], "원")
# 입력 3개 후 최대 값 출력.
number1 = int(input())
number2 = int(input())
number3 = int(input())
if number1 > number2:
print(number1)
elif number2 > number3:
print(number2)
else:
print(number3)
# 휴대전화 앞자리에 따라 통신사 출력
number = input("휴대전화 번호 입력 : ")
num = number.split("-")[0] // - 기준으로 나누고 맨 앞자리를 num에 저장
if num == "011":
com = "SKT"
elif num == "016":
com = "KT"
elif num == "019":
com = "LGU"
else:
com = "알수없음"
print(f"당신은 {com} 사용자입니다.")
# 우편번호 앞자리 3개로 판단해서 구 출력
우편번호 = input("우편번호: ")
우편번호 = 우편번호[:3]
if 우편번호 in ["010", "011", "012"]:
print("강북구")
elif 우편번호 in ["013", "014", "015"]:
print("도봉구")
else:
print("노원구")
# 주민번호로 남여 구분.
ID = input()
ID2 = ID.split("-")[1]
if ID2[0] == "1" or ID2[0] == "3":
print("남자")
else:
print("여자")
# 주민번호 뒷 자리 2,3 자리에 따라 출생지 출
# 00 ~ 08 = 서울, 09 ~ 12 = 부
id = input()
id2 = id.split("-")[1]
id3 = id2[1:3]
seoul = ["00", "01", "02", "03", "04", "05", "06", " 07", "08"]
busan = ["09", " 10", "11", "11"]
print(id3) // 확인용
if id3 in seoul:
print("서울 입니다.")
else:
print("부산 입니다.")