1. Comparison operators : > , < , >=, <=, ==(equal), !=(not equal to)
'=' 한번 쓴다는건, 이 값을 이 변수로 지정한다는 의미, '==' 두번 쓰는 것은 왼쪽과 오른쪽 값이 같은지 체크하는 것!
2. if (조건문) :
아래 나오는 박스에 조건문 삽입,
else:
if 조건문이 아닌 조건에 대한 조건문 (;)
3. (예제) 짝수인지 홀수인지 구분하기!
number = int(input("Which number do you want to check? "))
if number%2 == 0:
print("This is an even number.")
else:
print("This is an odd number.")
(...흠... 근데 0은 그럼 짝수인가?)
4. elif(elseif 사용하여 조건에 조건을 추가하기!)
4.1)
print("Welcome to the rollercoaster!")
height = int(input("What is your height in cm? "))
if height > 120:
print("you can ride the rollercoaster!")
age = input("what is your age?")
if age <12:
print("Please pay $5.")
elif age <=18:
print("please pay $7.")
else:
print("please pay $12.)")
else:
print("Sorry, you have to grow taller before you can ride")
4.2) BMI 계산하기
나)
BMI = weight / height**2
a = int(round(BMI))
안젤라)
BMI = round(weight / height **2) 이렇게 한번에 정의해 버림. 하긴 굳이 a라는 변수를 정의내릴 필요가 없잖아ㅋㅋㅋㅋ 그냥 bmi로 정의 내려 버렷....
if a < 18.5:
print(f"Your BMI is {BMI} you are underweight.") => 안젤라의 코딩; Fstring써서 좀더 쉽게 출력....
elif a <= 25:
print("Your BMI is " + str(a) + ", you have a normal weight.")=> 나의 코딩, a를 문자열로 변환해서 출력... 굳이 이렇게?(안젤라는 fstring설명하면서 서로 다른 데이터 유형을 통합할때 이렇게 쓰는건 고통스럽다고 표현함ㅋㅋㅋ ㅠㅠ)
<<정답>>
BMI 계산기 : https://replit.com/@hipi-noyenoye/day-3-2-exercise#main.py
day-3-2-exercise
Want to join the course? Start your journey here: https://100daysofpython.dev/
replit.com
height = float(input("enter your height in m: "))
weight = float(input("enter your weight in kg: "))
BMI = round(weight / height**2)
if BMI < 18.5:
print(f"Your BMI is {BMI} you are underweight.")
elif BMI < 25:
print(F"Your BMI is {BMI}, you have a normal weight.")
elif BMI < 30:
print(F"Your BMI is {BMI} you are slightly overweight.")
elif BMI < 35:
print(F"your BMI is {BMI} you are obese.")
else:
print(F"your BMI is {BMI} you are clinically obese.")
'10. 개발 > Python' 카테고리의 다른 글
파이썬 100days_4일차 가위바위보 출력하기 (0) | 2022.08.01 |
---|---|
파이썬 리스트 내용 바꾸기.... (0) | 2022.08.01 |
파이썬_랜덤 모듈 불러오기_python random module (0) | 2022.08.01 |
파이썬 modulo와 if else 활용한 윤년 계산기 (0) | 2022.07.30 |
파이썬의 숫자 처리_python 부트캠프 100days_day2 (0) | 2022.07.28 |