즐거운프로그래밍

[파이썬] 기초 다지기 if 문

수수께끼 고양이 2023. 10. 27. 12:25
728x90
반응형

 

if 문

냉장고에서 사과 찾기 1 (shell에서 실행하기)

fridge=["apple","pear","mandarine","banana"]
where=fridge.index('apple') #index
where
apple=fridge.pop(where) #pop
apple

 

 


냉장고에서 사과 찾기 2  (shell에서 실행하기)

fridge=["apple","pear","mandarine","banana"]
if 'apple' in fridge:
    where=fridge.index('apple')
    apple=fridge.pop(where)
    'eat'+apple

 

 


BMI 계산기

height=float(input('Enter your height in centimeters:'))
weight=float(input('Enter your weight in kg:'))
height/=100
BMI=weight/(height**2)
print(f'Your Body Mass Index is: {BMI}')
if BMI>0:
    if BMI<=16:
        print('You are serverely underweight')
    elif BMI<=18.5:
        print('You are underweight')
    elif BMI<=25:
        print('You are healthy')
    elif BMI<=30:
        print('You are overweight')
    else:
        print('You are serverely overweight')
else:
    print('Enter valid details')

 

 

 

 

728x90
반응형