11.[python기초 문제풀이]조건문(6.8)

Sooyeon·2023년 6월 8일

Python

목록 보기
11/22
post-thumbnail

[Python 기초 문제풀이]
조건문(01-06)

조건문(01)

#1.교통 과속 위반 프로그램을 만들어보자. 

speed=int(input( '속도 입력 : '))

if speed <= 50:
     print('안전속도 준수!!')

if speed >50:
    print('안전속도 위반!! 과태료 50,000원 부과 대상!!')
  

속도 입력 : 59
안전속도 위반!! 과태료 50,000원 부과 대상!!


#2.문자 메시지 길이에 따라 
   문자 요금이 결정되는 프로그램을 만들어보자.
  

messageInput = input('메세지 입력 :')
length = len(messageInput)

if length <= 50:
    print('SMS 발송!!')
    print('메세지 길이 : {}'.format(length))
    print('메세지 발송 요금 : 50원')

if length > 50:
    print('MMS 발송!!')
    print('메세지 길이 : {}'.format(length))
    print('메세지 발송 요금 : 100원')
   
메세지 입력 :안녕하세요.
SMS 발송!!
메세지 길이 : 6
메세지 발송 요금 : 50원    

조건문(02)

#1.국어,영어,수학, 과학, 국사 점수를 입력하면
총점을 비롯한 각종 데이터가 출력되는 프로그램을 만들어보자. 

korAvg=85; engAvg =82; matAvg =89; scienceAvg =75; historyAvg =94

kor=int(input('국어 : '))
eng=int(input('영어 : '))
mat=int(input('수학 : '))
science=int(input('과학 : '))
history=int(input('국사 : '))

totalScore = kor+eng+mat+science+history
avgTotal=korAvg+engAvg+matAvg+scienceAvg+historyAvg
avgAvg= int(avgTotal /5)
avgScore= int(totalScore /5)

print('-' *70)
print('총점: {}({}), 평균: {}({})'.format(totalScore,totalScore-avgTotal,avgScore,avgScore-avgAvg))
print('국어: {}({}), 영어: {}({}), 수학: {}({}), 과학: {}({}), 국사:{}({})'.format(kor,kor-korAvg,eng,eng-engAvg,\
mat,mat-matAvg,science,science-scienceAvg,history,history-historyAvg))
print('-' *70)

korSub=kor-korAvg
engSub=eng-engAvg
matSub=mat-matAvg
scienceSub=science-scienceAvg
histroySub=history-historyAvg
totalSub=totalScore -avgTotal
avgsub=avgScore-avgAvg


str ='+' if korSub >0 else '-'
print('국어 편차: {}({})'.format( str *  abs(korSub),korSub))
str ='+' if engSub >0 else '-'
print('영어 편차: {}({})'.format( str *  abs(engSub),engSub))
str ='+' if matSub >0 else '-'
print('수학 편차: {}({})'.format(str *  abs(matSub),matSub))
str ='+' if scienceSub >0 else '-'
print('과학 편차: {}({})'.format(str *  abs(scienceSub),scienceSub))
str ='+' if histroySub >0 else '-'
print('국사 편차: {}({})'.format(str *  abs(histroySub),histroySub))
str ='+' if totalSub >0 else '-'
print('총점 편차: {}({})'.format(str* abs(totalSub),totalSub))
str ='+' if avgsub >0 else '-'
print('평균 편차: {}({})'.format(str*abs(avgsub),avgsub))
print('-' *70)

국어 : 91
영어 : 92
수학 : 61
과학 : 58
국사 : 90
----------------------------------------------------------------------
총점: 392(-33), 평균: 78(-7)
국어: 91(6), 영어: 92(10), 수학: 61(-28), 과학: 58(-17), 국사:90(-4)
----------------------------------------------------------------------
국어 편차: ++++++(6)
영어 편차: ++++++++++(10)
수학 편차: ----------------------------(-28)
과학 편차: -----------------(-17)
국사 편차: ----(-4)
총점 편차: ---------------------------------(-33)
평균 편차: -------(-7)
----------------------------------------------------------------------

조건문(03)

# 1.난수를 이용해서 홀/짝 게임을 만들어보자.

import random
num =random.randint(1,2)
select = int(input('홀/짝 선택 : 1.홀    2.짝  '))

if num ==1 and select ==1:
    print('빙고!! 홀수 ')
elif num ==2 and select ==2:
    print('빙고!! 짝수 ')
elif num==1 and select==2:
    print('실패!! 홀수 ')
elif num==2 and select==1:
    print('실패!! 짝수 ')

홀/짝 선택 : 1.홀    2.짝  1
빙고!! 홀수 

# 2.난수를 이용해서 가위,바위,보 게임을 만들어보자. 


import random

computerNum=random.randint(1,3)
userNumber=int(input('가위,바위,보 선택 : 1.가위  2.바위  3.보  '))


if (computerNum ==1 and userNumber==2) or \
    (computerNum ==2 and userNumber==3) or\
    (computerNum ==3 and userNumber==1):
    print('컴퓨터 : 패 , 유저: 승')

elif computerNum == userNumber :
    print('무승부')

else: 
    print('컴퓨터 :승 , 유저: 패')


print('컴퓨터 : {} , 유저 : {} '.format(computerNum,userNumber))

조건문(04)

# 상수도 요금 계산기를 만들어보자.

choice = int(input('업종 선택(1.가정용    2.대중탕용    3.공업용): '))
useAmount=int(input('사용량 입력: '))

print('='*50)
print('상수도 요금표')
print('-'*50)
print('사용량    :    요금')

if choice ==2:
    if useAmount <= 50:
        print('{}    :    {}원'.format(useAmount,format((820 * useAmount),',')))
    elif useAmount <= 300 and useAmount > 50:
        print('{}    :    {}원'.format(useAmount,format((1920 * useAmount),',')))
    elif useAmount > 300:
        print('{}    :    {}원'.format(useAmount,format((2400 * useAmount),',')))

elif choice ==3:
    if useAmount <= 500:
        print('{}    :    {}원'.format(useAmount, format((240 * useAmount),',')))
    elif useAmount >500:
        print('{}    :    {}원'.format(useAmount, format((470 * useAmount),',')))

else:
    print('{}    :    {}원'.format(useAmount, format((540 * useAmount),',')))


업종 선택(1.가정용    2.대중탕용    3.공업용): 2
사용량 입력: 270
==================================================
상수도 요금표
--------------------------------------------------
사용량    :    요금
270    :    518,400원

조건문(05)

# 미세먼지 비상저감조치로 차량 운행제한 프로그램을 다음 내용에 맞게 만들어 보자.


import datetime
today=datetime.datetime.today()
day=today.day

dustInput= int(input('미세먼지 수치 입력 :'))
carType=int(input('차량 종류 선택 : 1.승용차    2.영업용차  '))
carNum=int(input('차량 번호 입력 :  ' ))

limitDust=150



print( '-' *50)
print(today)
print( '-' *50)

if dustInput >limitDust and carType ==1:
    if (day % 2) == (carNum % 2):
        print('차량 2부제 적용')
        print('차량 2부제로 금일 운행제한 대상 차량입니다.')
    else:
        print('금일 운행 가능합니다.')

if dustInput >limitDust and carType ==2:
    if (day % 5) == (carNum % 5):
        print('차량 5부제 적용')
        print('차량 5부제로 금일 운행제한 대상 차량입니다.')
    else:
        print('금일 운행 가능합니다.')

if dustInput <=limitDust:
    if(day%5) ==(carNum %5):
        print('차량 5부제 적용')
        print('차량 5부제로 금일 운행제한 대상 차량입니다.')
    else:
        print('금일 운행 가능합니다.')
print( '-' *50)


미세먼지 수치 입력 :145
차량 종류 선택 : 1.승용차    2.영업용차  1
차량 번호 입력 :  5526
--------------------------------------------------
2023-06-05 15:30:41.007062
--------------------------------------------------
금일 운행 가능합니다.


조건문(06)

# 1.PC에서 난수를 발생하면 사용자가 맞추는 게임을 만들어보자.

import random

comNum = random.randint(1,1000)
tryCnt=0
gameFlag=True

while gameFlag:
    tryCnt+= 1
    userNum=int(input('1에서 1000까지의 정수 입력 :'))

    if comNum == userNum:
        print(' 빙고!')
        gameFlag =False
    else:
       if comNum > userNum:
            print('난수가 크다!')
       else:
            print('난수가 작다!')

print('난수 : {} , 시도 횟수: {} '.format(comNum,tryCnt))


# 2.실내온도를 입력하면 스마트에어컨 상태가 자동으로 
설정되는 프로그램을 만들어보자. 


tempInput=int(input('실내온도 입력: '))

if tempInput <=18:
    print('에어컨: off')
elif tempInput <=22 and tempInput >18:
    print('에어컨: 매우 약!!')
elif tempInput <= 24 and tempInput > 22:
    print('에어컨:  약!!')
elif tempInput <26 and tempInput >24:
    print('에어컨 : 중!!')
elif tempInput <=28 and tempInput >26:
    print('에어컨:  강!!')
else:
    print('에어컨: 매우 강!!')


실내온도 입력: 29
에어컨: 매우 강!!

0개의 댓글