log.Sehee
[데이터 취업 스쿨 스터디 노트] 파이썬 기초문풀 2 - 3 본문
연산자 1
product_price = int(input('상품 가격 입력: '))
payment_price = int(input('지불 금액: '))
change = (payment_price - product_price) // 10 * 10
money = [50000, 10000, 5000, 1000, 500, 100, 10]
print(f'거스름 돈: {change}(원단위 절사)')
print('-' * 30)
for i in money:
if i >= 1000:
print(f'{i:,d} {change//i}장')
else:
print(f'{i} {change//i}개')
change %= i
print('-' * 30)

연산자 2
score = {'국어': 0,
'영어': 0,
'수학': 0
}
for k in score:
score[k] = int(input(f'{k} 점수 입력: '))
total = sum(score.values())
avg = total / 3
score = sorted(score.items(), key=lambda x: x[1])
high, row = score[2], score[0]
print('총점', total)
print(f'평균: {avg:.2f}')
print('-'*30)
print(f'최고 점수 과목(점수): {high[0]}({high[1]})')
print(f'최저 점수 과목(점수): {row[0]}({row[1]})')
print(f'최고, 최저 점수 차이: {high[1] - row[1]}')
print('-'*30)

연산자 3
hou = int(input('시간 입력: '))
min = int(input('분 입력: '))
sec = int(input('초 입력: '))
result = hou * 60 * 60 + min * 60 + sec
print(f'{result:,}초')

money = int(input('금액 입력: '))
rate = float(input('이율 입력: '))
date = int(input('기간 입력: '))
result = money
for _ in range(date):
result += result * 0.01 * rate
print('-'*30)
print(f'이율: {rate}%')
print(f'원금: {money:,}원')
print(f'{date}년 후 금액: {int(result):,}원')
print('-'*30)

연산자 4
height = int(input('고도 입력: '))
base_temp = 29
target_temp = base_temp - (height // 60 * 0.8)
if height % 60 != 0:
target_temp -= 0.8
print('지면 온도: 29')
print(f'고도 {height}m의 기온: {target_temp}')

bread = 197
milk = 152
student = 17
print('학생 한 명이 갖게 되는 빵 개수:', bread // student)
print('학생 한 명이 갖게 되는 우유 개수:', milk // student)
print('남는 빵 개수:', bread % student)
print('남는 우유 개수:', milk % student)

연산자 5
age = int(input('나의 입력: '))
calender = ['월', '화', '수', '목', '금', '월', '화,' '수', '목', '금']
if 19 < age < 65:
print('하반기 일정 확인하세요.')
else:
born = int(input('출생 연도 끝자리 입력: '))
print(f'{calender[born]}요일 접종 가능!!')

이 문제.. 강사님은 출생 연도 끝자리가 0인 경우에 금요일로 책정하셨는데
월요일을 0으로 하는 것이 더 깔끔한 것 같아 임의대로 변경하였다
by_inch = 0.039
length_mm = int(input('길이(mm) 입력: '))
length_inch = length_mm * by_inch
print(f'{length_mm}mm -> {length_inch}')

조건문 1
km = int(input('속도 입력: '))
print('안전속도 준수!!') if km <= 50 else print('안전속도 위반!! 과태료 50,000원 부과 대상!!!')

message = input('메세지 입력: ')
count = len(message)
print('SMS 발송!!')
print('메세지 길이:', count)
if count <= 50:
print('메세지 발송 요금: 50원')
else:
print('메세지 발송 요금: 100원')

조건문 2
subject = ['국어', '영어', '수학', '과학', '국사']
standard = [85, 82, 89, 75, 94]
score = []
deviation = []
for n in range(5):
score.append(int(input(f'{subject[n]} 점수 입력: ')))
deviation.append(score[n] - standard[n])
standard_total = sum(standard)
standard_avg = standard_total // 5
score_total = sum(score)
score_avg = score_total // 5
deviation_total = score_total-standard_total
deviation_avg = score_avg-standard_avg
print('-'*50)
print(f'총점: {score_total}({deviation_total}), 평균: {score_avg}({deviation_avg})')
for n in range(5):
if n == 4:
print(f'{subject[n]}: {score[n]}({deviation[n]})')
else:
print(f'{subject[n]}: {score[n]}({deviation[n]}), ', end='')
print('-'*50)
for n in range(5):
if deviation[n] > 0:
print(f'{subject[n]} 편차: {"+" * deviation[n]}({deviation[n]})')
else:
print(f'{subject[n]} 편차: {"-" * abs(deviation[n])}({deviation[n]})')
if deviation_total < 0:
print(f'총점 편차: {"-" * abs(deviation_total)}({deviation_total})')
else:
print(f'총점 편차: {"+" * deviation_total}({deviation_total})')
if deviation_avg < 0:
print(f'평균 편차: {"-" * abs(deviation_avg)}({deviation_avg})')
else:
print(f'평균 편차: {"+" * deviation_avg}({deviation_avg})')
print('-'*50)

조금 더 깔끔하게 쓸 수 있을 것 같은데 .. 오늘의 마음에 안드는 코드 BEST
기억 안나는 함수들이 생기고 구글링을 시작했다 ㅎㅎ.. 그래도 간만에 코드를 쓰니 재밌다~
더욱 깔끔하게 쓸 수 있도록 노력하기!
내일의 학습 목표
파이썬 기초문풀 4 - 5