오늘 감기때문인지 몸이 무거웠다.
공부는 왜 이리 하기 어려운건지.. 책상 앞에서 3시간이 지나도록 시작을 못했다.
오늘 분량을 해치우고 빨리 자자
파이썬 기초1
파이썬 기초2~3
파이썬 기초4
파이썬 기초5
파이썬 기초6
파이썬 기초7
파이썬 기초8
파이썬 기초9~10
파이썬 기초문풀1
파이썬 기초문풀2
파이썬 기초문풀3
📝 weekly 데이터 사이언스 스쿨 퀴즈
실습_01
체중(g)과 신장(cm)을 입력하면 BMI지수가 출력되는 프로그램을 만들어보자.
weight: 체중입력(g)
height: 신장입력(cm)
weight가 숫자라면 kg으로 환산
height가 숫자라면 m로 환산
BMI계산 (몸무게(kg) / 신장(m) * 신장(m)
weight = input('체중 입력(g): ')
height = input('신장 입력(cm): ')
if weight.isdigit():
weight = int(weight) / 10
if height.isdigit():
height = int(height) / 100
print('체중 : {}kg'.format(weight))
print('신장 : {}m'.format(height))
bmi = weight / (height * height)
print('BMI : %.2f' % bmi )
실습_02
다음 코드에서 num1과 num2의 값을 서로 바꾸고 각각 출력해보자.
num1 = 10
num2 = 20
print('num1: {}, num2: {}'.format(num1, num2))
tempNum = num1
num1 = num2
num2 = tempNum
print('num1: {}, num2: {}'.format(num1, num2))
실습_03
중간, 기말고사 점수를 입력하면 총점과 평균이 출력되는 프로그램을 만들어보자.
score1 = input('중간 고사 점수 : ')
score2 = input('기말 고사 점수 : ')
if score1.isdigit() and score2.isdigit(): # 형변환체크(숫자)_ .isdigit()함수
score1 = int(score1)
score2 = int(score2)
totalScore = score1 + score2
avgScore = totalScore / 2
print('총점: {}, 평균: {}'.format(totalScore, avgScore))
else:
print('잘 못 입력했습니다.')
실습_04
키오스크에서 사용 하는 언어 선택 프로그램을 만들어 보자.
selectNum = input('언어선택(choose your language) : 1.한국어 \t 2.English \t')
if selectNum == '1':
menu ='1.샌드위치 \t 2.햄버거 \t 3. 쥬스 \t 4.커피 \t 5.아이스크림'
if selectNum == '2':
menu ='1.Sandwich \t 2.Hamburger \t 3. Juice \t 4.Coffe \t 5.Ice cream'
print(menu)
실습_05
나의 나이가 100살이 되는 해의 연도를 구하는 프로그램을 만들어보자.
import datetime
today = datetime.datetime.today() # 년,월,일,시 출력함수
myAge = input('나이 입력 : ')
if myAge.isdigit():
afterAge = 100 - int(myAge)
my100 = today.year + afterAge
print('{}년({}년후)에 100살!'.format(my100, afterAge))
else:
print('잘 못 입력했습니다.')
실습_06
상품 가격과 지불금액을 입혁하면 거스름 돈을 계산하는 프로그램을 만들어보자.
단, 거스름돈은 제폐와 동전의 개수를 최소로 하고, 1원 단위를 절사한다.
money50000 = 50000; money10000 = 10000; money5000 = 5000; money1000 = 1000;
money500 = 500; money100 = 100; money10 = 10
money50000Cnt = 0; money10000Cnt = 0; money5000Cnt = 0; money1000Cnt = 0;
money500Cnt = 0; money100Cnt = 0; money10Cnt = 0
productPrice = int(input('상품 가격 입력: '))
payPrice = int(input('지불 금액 입력: '))
if payPrice > productPrice:
changeMoney = payPrice - productPrice
changeMoney = (changeMoney // 10) * 10
print('거스름 돈 : {}(원단위 절사)'.format(changeMoney))
if changeMoney > money50000:
money50000Cnt = changeMoney // money50000
changeMoney %= money50000
if changeMoney > money10000:
money10000Cnt = changeMoney // money10000
changeMoney %= money10000
if changeMoney > money5000:
money5000Cnt = changeMoney // money5000
changeMoney %= money5000
if changeMoney > money1000:
money50000Cnt = changeMoney // money1000
changeMoney %= money1000
if changeMoney > money500:
money500Cnt = changeMoney // money500
changeMoney %= money500
if changeMoney > money100:
money100Cnt = changeMoney // money100
changeMoney %= money100
print('-' * 36)
print('50,000 {}장'.format(money50000Cnt))
print('10,000 {}장'.format(money10000Cnt))
print('5,000 {}장'.format(money5000Cnt))
print('1,000 {}장'.format(money1000Cnt))
print('500 {}개'.format(money500Cnt))
print('100 {}개'.format(money100Cnt))
print('10 {}개'.format(money10Cnt))
print('-' * 36)
실습_07
국어, 영어, 수학 점수 입력후, 총점, 평균, 최고점수 과목/최저점수 과목 그리고 최고점수와 최저 점수의 차이를 각각 출력해보자.
korScore= int(input('국어 점수 입력 : '))
engScore= int(input('영어 점수 입력 : '))
matScore= int(input('수학 점수 입력 : '))
totalScore = korScore + engScore + matScore
avgScore = totalScore / 3
maxScore = korScore
maxSubject = '국어'
if engScore > maxScore:
maxScore = engScore
maxSubject = '영어'
if matScore > maxScore:
maxScore = matScore
maxSubject = '수학'
minScore = korScore
minSubject = '국어'
if engScore < minScore:
minScore = engScore
minSubject = '영어'
if matScore < minScore:
minScore = matScore
minSubject = '수학'
difScore = maxScore - minScore
print(f'총점: {totalScore}')
print('평균: %.2f' % avgScore)
print('-' * 36)
print(f'최저 점수 과목(점수): {maxSubject}({maxScore})')
print(f'최저 점수 과목(점수): {minSubject}({minScore})')
print(f'최고, 최저 점수 차이: {difScore}')
print('-' * 36)
실습_08
시, 분, 초를 입력하면 초로 호나산하는 프로그램을 만들어 보자.
hou = int(input('시간 입력 : '))
min = int(input('분 입력 : '))
sec = int(input('초 입력 : '))
print('{}초'.format(format(hou * 60 * 60 + min * 60 + sec, ',')))
실습_09
금액, 이율, 거치기간을 입력하면 복리ㅣ계산하는 복리계산기 프로그램을 만들어 보자.
money = int(input('금액 입력 : '))
rate = float(input('이율 입력 : ')) # 4.3 %
term = int(input('기간 입력 : '))
targetMoney = money
for i in range(term):
targetMoney+= (targetMoney * rate * 0.01)
targetMoneyFormated = format(int(targetMoney), ',') # 원단위 콤마찍기
moneyformated = format(int(money), ',') # 원단위 콤마찍기
print('-' * 36)
print(f'이율: {rate}')
print(f'원금: {moneyformated}')
print(f'{term}년 후 금액: {targetMoneyFormated}원')
print('-' * 36)
실습_10
고도가 60m 올라갈때마다 기온이 0.8도 내려간다고 할때 고도를 입력하면 기온이 출력되는 프로그램을 만들어보자.(지면온도:29도)
baseTemp = 29
step = 60
stepTemp = 0.8
height = int(input('고도 입력 : '))
targetTemp = baseTemp -((height // step) * 0.8)
if height % step != 0:
targetTemp -= stepTemp
print(f'지면온도: {baseTemp}')
print(f'고도 {height}m의 기온: {targetTemp}')
실습_11
백신 접종 대상자를 구분하기 위한 프로그램을 만들어 보자.
inputAge = int(input('나이 입력: '))
if inputAge <= 19 or inputAge >= 65:
endNum = int(input('출생연도 끝자리 입력: '))
if endNum == 1 or endNum == 6:
print('월요일 접종 가능!')
elif endNum == 2 or endNum == 7:
print('화요일 접종 가능!')
elif endNum == 3 or endNum == 8:
print('수요일 접종 가능!')
if endNum == 4 or endNum == 9:
print('목요일 접종 가능!')
elif endNum == 5 or endNum == 0:
print('금요일 접종 가능!')
else:
print('하반기 일정을 확인하세요.')
실습_12
길이(mm)를 입력하면 inch로 환산하는 프로그램을 만들어보자.
1mm = 0.039inch
byInch = 0.039
lengthmm = int(input('길이(mm) 입력 :'))
lengthInch = lengthmm * byInch
print(f'{lengthmm}mm -> {lengthInch}inch')
실습_13
교통 과속 위반 프로그램을 만들어보자.
시속 50km이하 안전속도 준수!!
시속 50km초과 안전속도 위반!! 과태표 50,000원 부과 대상!!!
carSpeed = int(input('속도 입력: '))
limitSpeed = 50
if carSpeed > 50:
print('안전속도 위반!! 과태료 50,000원 부과 대상!!!')
else:
print('안전속도 준수!!')
실습_14
문자 메시지 길이에 따라 문자 요금이 결정되는 프로그램을 만들어보자
문자 길이 50이하 SMS발송(50원 부과)
문자 길이 50초과 MMS발송(100원 부과)
message = input('메세지 입력:')
lenMessage = len(message)
msgPrice = 50
if lenMessage <= 50:
msgPrice = 50
print('SMS 발송!!')
else:
msgPrice = 100
print('MMS 발송!!')
print(f'메세지 길이 : {lenMessage}')
print(f'메세지 발송 요금: {msgPrice}원')
실습_15
국어, 영어, 수학, 과학, 국사 점수를 입력하면 총점을 비롯한 각종 데이터가 출력되는 프로그램을 만들어보자.
목별 점수를 입력하면 총점, 평균, 편차를 출력한다. 평균은 다음과 같다.
(국어: 85, 영어: 82, 수학: 89, 과학: 75, 국사: 94)
각종 편차 데이터는 막대그래프로 시각화한다.
korAvg = 85; engAvg = 82; matAvg = 89
sciAvg = 75; hisAvg = 94
totalAvg= korAvg + engAvg + matAvg + sciAvg + hisAvg
avgAvg = int(totalAvg / 5)
korScore = int(input('국어 점수 : '))
engScore = int(input('영어 점수 : '))
matScore = int(input('수학 점수 : '))
sciScore = int(input('과학 점수 : '))
hisScore = int(input('국사 점수 : '))
totalScore = korScore + engScore + matScore + sciScore + hisScore
avgSCore = int(totalScore / 5)
korGap = korScore - korAvg
engGap = engScore - engAvg
matGap = matScore - matAvg
sciGap = sciScore - sciAvg
hisGap = hisScore - hisAvg
totalGap = totalScore - totalAvg
avgGap = avgSCore - avgAvg
print('-' * 80)
print(f'총점: {totalScore}({totalGap}), 평균: {avgSCore}({avgGap})')
print(f'국어: {korScore}({korGap}), 영어: {engScore}({engGap}), 수학: {matScore}({matGap}),'
f'과학: {sciScore}({sciGap}), 국사: {hisScore}({hisGap})')
str = '+' if korGap > 0 else '-'
print('국어 편차: {}({})'.format(str * abs(korGap), korGap))
str = '+' if engGap > 0 else '-'
print('영어 편차: {}({})'.format(str * abs(engGap), engGap))
str = '+' if matGap > 0 else '-'
print('수학 편차: {}({})'.format(str * abs(matGap), matGap))
str = '+' if sciGap > 0 else '-'
print('과학 편차: {}({})'.format(str * abs(sciGap), sciGap))
str = '+' if hisGap > 0 else '-'
print('국사 편차: {}({})'.format(str * abs(hisGap), hisGap))
str = '+' if totalGap > 0 else '-'
print('총점 편차: {}({})'.format(str * abs(totalGap), totalGap))
str = '+' if avgGap > 0 else '-'
print('평균 편차: {}({})'.format(str * abs(avgGap), avgGap))
print('-' * 80)
언능 끝내고 쉬고 싶다...
컨디션 조절을 잘 해야 롱런 할수 있다.