[Python] 기초 문제풀이 (2)

강미진·2023년 4월 12일

연산자

  • 상품 가격과 지불 금액을 입력하면 거스름 돈을 계산하는 프로그램
    (단,거스름 돈은 지폐와 동전의 개수를 최소로 하고 1원 단위 절사)
product_price = int(input('상품 가격 입력 : '))
pay_price = int(input('지불 금액 : '))
money_50000 = 50000 ; money_10000 = 10000 ; money_5000 = 5000 ; money_1000 = 1000 ; money_500 = 500
money_100 = 100 ; money_50 = 50 ; money_10 = 10
## money_count
money_50000cnt = 0 ; money_10000cnt = 0 ; money_5000cnt = 0 ; money_1000cnt = 0 ; money_500cnt = 0
money_100cnt= 0 ; money_50cnt = 0 ; money_10cnt = 0
##charge system
if pay_price > product_price :
    charge = pay_price - product_price
    charge = (charge //10)*10
    print('거스름 돈 : {}(원단위 절사)'.format(charge))
if charge >= money_50000 :
    money_50000cnt = charge // money_50000
    charge %= money_50000
if charge >= money_10000 :
    money_10000cnt = charge // money_10000
    charge %= money_10000
if charge >= money_5000 :
    money_5000cnt = charge // money_5000
    charge %= money_5000
if charge >= money_1000 :
    money_1000cnt = charge // money_1000
    charge %= money_1000
if charge >= money_500 :
    money_500cnt = charge // money_500
    charge %= money_500
if charge >= money_100 :
    money_100cnt = charge // money_100
    charge %= money_100
if charge >= money_50 :
    money_50cnt = charge // money_50
    charge %= money_50
if charge >= money_10 :
    money_10cnt = charge // money_10
    charge %= money_10
상품 가격 입력 : 32658
지불 금액 : 100000
거스름 돈 : 67340(원단위 절사)
------------------------------
50,000 1장
10,000 1장
5,000 1장
1,000 2장
500 0장
100 3장
50 0장
10 4장
------------------------------
  • 국어, 영어, 수학 점수 입력 후 총점, 평균, 최고점수 과목, 최저점수 과목, 그리고 최고 점수와 최저 점수의 차이를 각각 출력
kor_score = int(input('국어 점수 입력 : '))
eng_score = int(input('영어 점수 입력 : '))
mat_score = int(input('수학 점수 입력 : '))
# score sum and avg ----------------------------
total_score = kor_score + eng_score + mat_score
avg_score = total_score / 3
# max score ------------------------------------
max_score = kor_score
max_subject = '국어'
# logic ----------------------------------------
if eng_score > max_score :
    max_score = eng_score
    max_subject = '영어'
if mat_score > max_score :
    max_score = mat_score
    max_subject = '수학'
min_score = kor_score
min_subject = '국어'
if eng_score < min_score :
    min_score = eng_score
    min_subject = '영어'
if mat_score < min_score :
    min_score = mat_score
    min_subject = '수학'
# print ----------------------------------------
print('총점 : {}'.format(total_score))
print('평균 : %.2f'%avg_score)
dif_score = max_score - min_score
print('-'*30)
print('최고 점수 과목(점수) : {}({})'.format(max_score, max_subject))
print('최저 점수 과목(점수): {}({})'.format(min_score, min_subject))
print('최고, 최저 점수 차이 : {}'.format(dif_score))
print('-'*30)
------------------------------
국어 점수 입력 : 85
영어 점수 입력 : 95
수학 점수 입력 : 100
총점 : 280
평균 : 93.33
------------------------------
최고 점수 과목(점수) : 100(수학)
최저 점수 과목(점수): 85(국어)
최고, 최저 점수 차이 : 15
------------------------------
  • 시, 분, 초를 입력하면 초로 환산하는 프로그램
hour = int(input('시간 입력 : '))
min = int(input('분 입력 : '))
sec = int(input('초 입력 : '))
print('{}초'. format(hour * 60 * 60 + min * 60 + sec))
시간 입력 : 5
분 입력 : 6
초 입력 : 30
18390초
  • 금액, 이율, 거치기간을 입력하면 복리계산하는 복리계산기 프로그램
deposit = int(input('금액 입력 : '))
interest_rate = float(input('이율 입력 : '))
duration = int(input('기간 입력 : '))
after_term = deposit
# for --------------------------------------
for i in range (duration) :
    after_term += after_term * (interest_rate * 0.01)
deposit=format(deposit,',')
after_term_formed = format(int(after_term), ',')
# print ------------------------------------
print('-'*30)
print('이율 : {}%' .format(interest_rate))
print('원금 : {}원' .format(deposit))
print('{}년 후 금액 : {}원'.format(duration,after_term_formed))
print('-'*30)
금액 입력 : 520000
이율 입력 : 4.3
기간 입력 : 2
------------------------------
이율 : 4.3%
원금 : 520,000원
2년 후 금액 : 565,681원
------------------------------
  • 고도가 60m 올라갈 때마다 기온이 0.8도 내려간다고 할 때 고도를 입력하면 기온이 출력되는 프로그램을 만들어보자
    (지면온도 : 29℃)
baseTemp = 29
step = 60
step_temp = 0.8
height = int(input('고도 입력 : '))
targetTemp = baseTemp - ((height // step) * 0.8)
# logic -------------------------------------------
if height % step != 0 :
    targetTemp -= step_temp
# print -------------------------------------------
print('지면 온도 : {}'.format(baseTemp))
print('고도 {}m의 기온 : {}'.format(height, targetTemp))
고도 입력 : 1800
지면 온도 : 29
고도 1800m의 기온 : 5.0
  • 197개의 빵과 152개의 우유를 17명에게 나눠줄 때, 한 명의 학생이 갖게 되는 빵과 우유 개수를 출력
bread = 197
milk = 152
student = 17
# print ---------------------------------------------
print('힉생 한 명이 갖게 되는 빵 개수 : {}'.format(bread//17))
print('힉생 한 명이 갖게 되는 우유 개수 : {}'.format(milk//17))
print('남는 빵 개수 : {}'.format(bread % student))
print('남는 우유 개수 : {}'.format(milk % student))
힉생 한 명이 갖게 되는 빵 개수 : 11
힉생 한 명이 갖게 되는 우유 개수 : 8
남는 빵 개수 : 10
남는 우유 개수 : 16
  • 백신 접종 대상자를 구분하기 위한 프로그램 제작
    19세 이하 또는 25세 이상이면 출생 연도 끝자리에 따라 접종, 그렇지 않으면 하반기 일정 확인
user_age = int(input('나이 입력 : '))
if user_age <= 19 or user_age >=65 :
    born_year = input('출생 연도 입력 : ')
    if born_year[3] == '1' or born_year[3] == '6' :
        print('월요일 접종 가능')
    elif born_year[3] == '2' or born_year[3] == '7' :
        print('화요일 접종 가능')
    elif born_year[3] == '3' or born_year[3] == '8' :
        print('수요일 접종 가능')
    elif born_year[3] == '4' or born_year[3] == '9' :
        print('목요일 접종 가능')
    elif born_year[3] == '5' or born_year[3] == '0' :
        print('금요일 접종 가능')
else :
     print('하반기 일정 확인하세요.')
나이 입력 : 12
출생 연도 입력 : 2012
화요일 접종 가능
  • 길이(mm)를 입력하면 inch로 환산하는 프로그램
    1mm = 0.039inch
inch = 0.039
length_mm = int(input('길이( mm) 입력 : '))
length_inch = length_mm * inch
print('{}mm → {}inch'.format(length_mm, length_inch))
길이( mm) 입력 : 560
560mm → 21.84inch
profile
g'day mate

0개의 댓글