Python Basic_조건식

jaam._.mini·2023년 11월 5일
0

📒Python 기초 수학

목록 보기
4/46

😁 생각보다 조건식, 너무 재밌다..?

오늘의 목차

  • 기본식
  • if ()
  • if else ()
  • if elif ()
  • 중첩조건문

📌 조건식 기본식

A if 조건식 else B : 조건식의 결과가 ture면 A실행, False면 B실행❗

num1 = 10
num2 = 100
numResult = True if num1 > num2 else False
print('num1 > num2 : {}' .format(numResult))

📌 if ()

True면 실행, False면 아무일도 일어나지 않음

📍 실내 온도 입력, 온도 28 이상:냉방 작동, 20이하:난방작동

highTem = 28
lowTem = 20
innerTem = int(input('실내 온도 : '))

if innerTem >= highTem:
	print('냉방 작동')
if innerTem <= lowTem:
	print('난방 작동')

📌 if else ()

둘중 하나 실행❗

📍 계절 출력

print('계절 : 봄, 여름, 가을, 겨울')
season = input('계절 입력 : ')
if season == '봄':
    print('{}'.format('Spring'))
if season == '여름':
    print('{}'.format('Summer'))
if season == '가을':
    print('{}'.format('Atum'))
if season == '겨율':
    print('{}'.format('Winter'))
else:
    print('알 수 없습니다.')
    
📍 성적 출력

exampleScore = int(input('시험 성적 : '))
grades = ''
if exampleScore >= 90:
    grades = 'A'
if exampleScore >= 80:
    grades = 'B'
if exampleScore >= 70:
    grades = 'C'
if exampleScore >= 60:
    grades = 'D'
else:
    grades = 'F'
print('성적: {}\t 학점: {}'.format(exampleScore, grades))

📌 if elif ()

📍키오스크에서 메뉴를 선택하면 영수증이 출력되는 프로그램 만들기

print('1.카페라떼(3.5) \t 2.에스프레소(3.0) \t 3.아메리카노(2.0)')
userSelect = int(input('메뉴 : '))
print('-' * 25)
if userSelect == 1:
    print('메뉴 : 카페라떼')
    print('가격 : 3,500원')
elif userSelect == 2:
    print('메뉴 : 에스프레소')
    print('가격 : 3,000원')
elif userSelect == 3:
    print('메뉴 : 아메리카노')
    print('가격 : 2,000원')
else:
    print('없는 메뉴 입니다.')
print('-' * 25)

📌 중첩조건문

조건문 안에 또 다른 조건문이 존재❗

#교통수단에 따라 세금 감면
#출퇴근 대상인가?
#대상자 : 도보/자전거 5%감면, 버스/지하철 3%감면, 차 1% 추가징수
#출퇴근 대상자가 아니면 세금 변동 없음

select = int(input('출퇴근 대상자? 1.yes \t 2.no'))

if select == 1:
    print('교토수단을 선택하세요')
    trans = int(input('1.도보/자전거 \t 2.버스/지하철\t 3.차') )

    if trans == 1:
        print('5% 감면')
    elif trans == 2:
        print('3% 감면')
    elif trans == 3:
        print('1% 추가 징수')
elif select == 2:
    print('변동 없음')
else:
    print('잘못 입력했습니다.')

# 제로베이스 데이터 취업 스쿨
# Daily study note
profile
비전공자의 데이터 공부법

0개의 댓글