πŸŒ€ 파이썬 Python

파이썬 - Datetime & if 쑰건문

Meteora_ 2021. 6. 26. 23:58
728x90
number = 12

if number > 0:
    print("0보닀 크닀")
    

    if number < 10:
        print("10보닀적닀")


if number == 0:
    print("0μž…λ‹ˆλ‹€")

#날씨와 μ‹œκ°„μ„ 취득
import datetime 

#ν˜„μž¬ λ‚ μ§œ/μ‹œκ°„
now = datetime.datetime.now()
print(now.year, 'λ…„')
print(now.month, 'μ›”')
print(now.day, '일')
print(now.hour, 'μ‹œ')
print(now.minute, 'λΆ„')

if now.hour < 12:
    print('ν˜„μž¬ μ‹œκ°„μ€ {}μ‹œλ‘œ μ˜€μ „μž…λ‹ˆλ‹€'.format(now.hour))
if now.hour >= 12:
    print('ν˜„μž¬ μ‹œκ°„μ€ {}μ‹œλ‘œ μ˜€ν›„μž…λ‹ˆλ‹€'.format(now.hour))


#μ‹œκ°„μ„€μ •
    setTime = datetime.datetime.strptime('2021-05-06 12:35:45','%Y-%m-%d %H:%M:%S')
    print(setTime)

#μ‹œκ°„λ³€κ²½
    setTime = setTime.replace(year=2022)
    setTime = setTime.replace(hour=18)
    
# κ³„μ ˆ ꡬ뢄
if now.month >= 3 and now.month <= 5:
    print("이 달은{}μ›”λ‘œ λ΄„μž…λ‹ˆλ‹€".format(now.month))


if 3<= now.month and now.month <= 5:
    print("이 달은{}μ›”λ‘œ λ΄„μž…λ‹ˆλ‹€".format(now.month))


number = 245
if number % 2 != 0:
    print('ν™€μˆ˜μž…λ‹ˆλ‹€')

month = datetime.datetime.now().month

if 3 <= month <= 5:
    print('λ΄„μž…λ‹ˆλ‹€')
    elif 6 <= month <= 8:
        print('μ—¬λ¦„μž…λ‹ˆλ‹€')
         elif 9 <= month <= 11:
             print('κ°€μ„μž…λ‹ˆλ‹€')
             else:
                 print('κ²¨μšΈμž…λ‹ˆλ‹€')


# pass
 number = int(input("μ •μˆ˜μž…λ ₯ > "))

 if number > 0:
     # λ―Έκ΅¬ν˜„
     print('number > 0')
     pass

else:
    # λ―Έκ΅¬ν˜„
    pass



 if number > 0:
     # λ―Έκ΅¬ν˜„

     raise NotImplementedError
     

else:
   raise NotImplementedError
     
 
과제

'''
BMI (Body Mass Index)
건강을 μœ„ν•΄ λΉ„λ§Œλ„λ₯Ό μ²΄ν¬ν•˜μ—¬ λ΄…μ‹œλ‹€. 
μ‹ μž₯κ³Ό 체쀑을 μž…λ ₯ν•˜κ³  λ‹Ήμ‹ μ˜ λΉ„λ§Œλ„ (BMI = 체쀑 (kg) ÷ μ‹ μž₯ (m)의 제곱)을 κ³„μ‚°ν•˜λŠ” ν”„λ‘œκ·Έλž¨μ„ μž‘μ„±ν•˜κ³  계산 κ²°κ³Όλ₯Ό ν™•μΈν•˜μ‹­μ‹œμ˜€.
νŒμ • κΈ°μ€€ 18.5 미만 → 마λ₯Έ, 18.5 ~ 25 미만 → ν‘œμ€€ 25-30 미만 → λΉ„λ§Œ, 30 이상 → 고도 λΉ„λ§Œμ΄λ˜κ³  μžˆλŠ” 것 κ°™μŠ΅λ‹ˆλ‹€.

ν‚€λ₯Ό cm λ‹¨μœ„λ‘œ μž…λ ₯ν•˜μ‹­μ‹œμ˜€> 170
체쀑을 kg λ‹¨μœ„λ‘œ μž…λ ₯ν•˜μ‹­μ‹œμ˜€> 65
BMI = 22.49134948096886
당신은 "ν‘œμ€€"μž…λ‹ˆλ‹€.
'''

height = int(input('ν‚€λ₯Ό cm λ‹¨μœ„λ‘œ μž…λ ₯ν•˜μ‹­μ‹œμ˜€>'))
kg = int(input('체쀑을 kg λ‹¨μœ„λ‘œ μž…λ ₯ν•˜μ‹­μ‹œμ˜€>'))

bmi = kg / ((height/100)**2)
print("BMI =",bmi)

if bmi < 18.5:
    print("당신은'마λ₯Έ'μž…λ‹ˆλ‹€")
elif 18.5 <= bmi <25:
    print("당신은'ν‘œμ€€'μž…λ‹ˆλ‹€")
elif 25 <= bmi <30:
    print("당신은'λΉ„λ§Œ'μž…λ‹ˆλ‹€")
else :
        print("κ³ λ„λΉ„λ§Œ")





'''
μœ€λ…„μ˜ νŒμ •
μœ€λ…„μ΄λΌλŠ” 것은 4 년에 ν•œ 번, 이월 29 μΌκΉŒμ§€ λͺ‡ λ…„μ˜ 것을 λ§ν•˜λ©΄ μƒκ°λ˜κ³  μžˆμŠ΅λ‹ˆλ‹€λ§Œ, μ •ν™•ν•˜κ²ŒλŠ” 더 λ³΅μž‘ν•©λ‹ˆλ‹€. 
첫번째 연도λ₯Ό 400으둜 λ‚˜λˆŒ 경우, μœ€λ…„μž…λ‹ˆλ‹€.
λ‘λ²ˆμ§Έλ‘œ 연도λ₯Ό 100으둜 λ‚˜λˆŒ 수 μžˆλ‹€λ©΄, μœ€λ…„μœΌλ‘œ ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.        예) 123
μ„Έλ²ˆμ§Έλ‘œ 연도λ₯Ό 4둜 λ‚˜λˆŒ 수 μžˆλ‹€λ©΄ μœ€λ…„μž…λ‹ˆλ‹€.

이 κ·œμΉ™μ— 따라 μ„œκΈ° 연도λ₯Ό μž…λ ₯ν•˜κ³  μœ€λ…„μ„ 확인할 μˆ˜μžˆλŠ” ν”„λ‘œκ·Έλž¨μ„ μž‘μ„±ν•©λ‹ˆλ‹€.
μ„œκΈ° 연도λ₯Ό μž…λ ₯ν•˜μ‹­μ‹œμ˜€> 1996
1996 년은 μœ€λ…„μž…λ‹ˆλ‹€.
'''

year = eval(input("μ„œκΈ° 연도λ₯Ό μž…λ ₯ν•˜μ‹­μ‹œμ˜€>"))
LYear = (year % 4 == 0 and (year % 100!=0) 
or (year % 400 == 0))

if LYear == True:
    print("μœ€λ…„μž…λ‹ˆλ‹€")

print(year, "년은 μœ€λ…„μΈμ§€ νŒλ³„", LYear)