250605 파이썬 공부

SEHEE·2025년 6월 5일
0

오늘 깨달은것

  • 딕셔너리 = 이름표 붙은 선물 상자 >> 리스트랑 헷갈리면 안된다. value 값 뽑고싶으면 [key] key 제대로 입력해야함.
    -sales_records.values ← 자판기를 가리킴만 함
    sales_records.values() ← 버튼을 눌러서 진짜 아이스크림이 나옴!
    =>> 괄호의 중요성! 괄호 꼭 넣어야함.
  • str() 숫자를 글자로 바꾸는 마법 + 문자열을 붙이는 도구
  • f"{}" 값을 중간에 넣는 빠르고 쉬운 방법
  • .items() 반복문 쓸 때 키-값 쌍을 하나씩 꺼낼 때 사용
  • 작성한 것 자료형 (종류) 뜻
    True 불(Boolean) 진짜 "참이다!" ✅
    'true' 문자열(str) 그냥 글자 "t-r-u-e" 📦
    ==> 참 거짓 나눌때는 대문자로 하자. True로.
  • not is_raining
    (같은 표현) is_raining==false
  • 조건문 true라면 그냥 조건문에 표현 안해도됨
    ex)
    hascoupon = True
    item_price = 15000
    if item_price > 10000 and _has_coupon
    :
    print("할인 혜택을 받을 수 있습니다.")
    else:
    print("할인 혜택을 받을 수 없습니다.")

미니과제 풀이

미니과제 2주차 딕셔너리

Level. 1
1-1.
person_info={'name':'김철수', 'age':25}
print(person_info)
1-2.
person_info={'name':'김철수', 'age':25}
print(person_info['name'])
1-3.
city_population = {'서울': 970, '부산': 340}
city_population['제주']=67
print(city_population)
1-4.
stock_price = {'삼성전자': 80000, 'SK하이닉스': 120000}
stock_price['삼성전자']=82000
print(stock_price)
1-5
student_grades = {'민수': 90, '지영': 85, '태호': 70}
del student_grades['태호']
print(student_grades)

Level. 2
2-1.
product_details = {'name': '노트북', 'price': 1200000, 'brand': 'LG'}
keys=product_details.keys()
print(keys)
2-2.
product_details = {'name': '노트북', 'price': 1200000, 'brand': 'LG'}
values=product_details.values()
print(values)
2-3.
🔥
2-4.
풀었는데 다시 고민하며 해결해보기 🔥🔥contact_info={'이름': '박영희', '전화번호': '010-1234-5678', '이메일': 'pyh@example.com'}
del contact_info['이메일']
print(contact_info)
2-5.
book_info = {'title': '어린 왕자', 'author': '앙투안 드 생텍쥐페리', 'year': 1943}
a= book_info.items()
print((a))

Level. 3
3-1.
student_data = {'id': 's001', 'name': '이하나', 'grades': {'수학': 85, '영어': 92}}
math_score = student_data['grades']['수학']
print("수학 점수:", math_score)
3-2.
product_catalog = {'A101': {'name': '키보드', 'price': 50000}, 'B202': {'name': '마우스', 'price': 25000}}
product_catalog['C303']=[{'name': '모니터', 'price': 200000}]
print(product_catalog)
3-3.
event_schedule = {'2025-06-01': ['회의', '발표 준비'], '2025-06-02': ['워크숍']}
event_schedule['2025-06-01'].append('점심 식사') # 리스트에 추가
print(event_schedule)
3-4.
sales_records = {'Q1': 1500, 'Q2': 1800, 'Q3': 1200, 'Q4': 2000}
#딕셔너리의 값들만 추출하여 max()와 min() 함수 사용
max_sales = max(sales_records.values())
min_sales = min(sales_records.values())
print("가장 높은 판매 실적:", max_sales)
print("가장 낮은 판매 실적:", min_sales)
3-5.
inventory = {'사과': 100, '바나나': 50, '오렌지': 75}
#각 키와 값에 직접 접근하여 출력
print("과일: 사과, 재고: " + str(inventory['사과']) + "개")
print("과일: 바나나, 재고: " + str(inventory['바나나']) + "개")
print("과일: 오렌지, 재고: " + str(inventory['오렌지']) + "개")

미니과제 3주차 -1

Level. 1
1-1.
score=[75]
score=0
if score>= 60 :
print("합격입니다.")
else:
print("불합격입니다.")
1-2.
age=15
if age>=19:
print("성인입니다!")
else:
print("미성년자입니다!")
1-3.
number=0
if number>0:
print("양수입니다.")
elif number==0:
print("0입니다.")
elif number<0:
print("음수입니다.")
1-4.
is_sunny = True
if is_sunny: # is_sunny == True 와 같습니다.
print("오늘은 화창한 날입니다.")
1-5
value1=10
value2=20
if value1==value2:
print("두 값은 같습니다")
elif value1!=value2:
print("두 값은 다릅니다")

Level. 2
2-1.
user_score=int(input("점수를 입력해주세요."))
if user_score>=90:
print("A학점")
elif user_score>=80:
print("B학점")
elif user_score>=70:
print("C학점")
else:
print("F학점")
2-2.
temp=28
is_raining=False
if temp>=25 and is_raining==False:
print("산책하기 좋은 날씨 입니다.")
else :
print("실내활동을 추천합니다.")
2-3.
user_age=int(input("나이 입력해줘"))
if user_age<10 or user_age>=65:
print("무료입장입니다.")
else :
print("입장료가 있습니다")
2-4.
has_coupon=True
item_price=15000
if item_price>10000 and has_coupon==True:
print("할인 혜택 받기 가능")
else:
print("할인 혜택 받기 불가능")
2-5.
-1)
user_id='admin'
user_password= '1234'
if user_id=='admin' and user_password !='password':
print("관리자 로그인 성공!")
else:
print("로그인 실패:ID 또는 비밀번호 오류")
-2)
user_id='admin'
user_password= '1234'
if user_id=='admin' and not(user_password =='password'):
print("관리자 로그인 성공!")
else:
print("로그인 실패:ID 또는 비밀번호 오류")

Level. 3
3-1.

height=int(input("키를 입력해주세요!"))
weight=int(input("몸무게를 입력해주세요!"))
BMI= weight/((height/100)2)
if BMI>=25:
print("비만입니다!")
elif 18.5<=BMI<25:
print("정상체중입니다.")
else :
print("저체중입니다.")
print(BMI)

3-2

profile
안녕하세요! 마케터를 꿈꾸는 취준생입니다 :)

0개의 댓글