코드업 기초3. if ~ else (3)

Tino-Kim·2022년 1월 23일
0
post-thumbnail

🥴 코드업 기초3. if ~ else (3)

📌 조건문 if ~ elif ~ else

  • 조건문은 조건만 잘 생각해주면 잘 풀어낼 수 있다.
# 1206
a,b=map(int, input().split())
if a>b:
    if a%b==0:
        x=a//b
        print(f'{b}*{x}={a}')
    else:
        print('none')
else:
    if b%a==0:
        x=b//a
        print(f'{a}*{x}={b}')
    else:
        print('none')
        
# 1207
from sys import stdin
a,b,c,d=map(int, stdin.readline().split())
_list=[a,b,c,d]

count_1=0
for ii in _list:
    if ii == 1:
        count_1+=1
        
if count_1==0:
    print('모')
elif count_1==1:
    print('도')
elif count_1==2:
    print('개')
elif count_1==3:
    print('걸')
else:
    print('윷')
    
# 1210
a,b=map(int, input().split())
menu={1:400, 2:340, 3:170, 4:100, 5:70}
if menu[a]+menu[b]>500:
    print('angry')
else:
    print('no angry')

# 1212
from sys import stdin
a,b,c=map(int, stdin.readline().split())
_list=[a,b,c]
_list=sorted(_list)
if _list[0]+_list[1]>_list[-1]:
    print('yes')
else:
    print('no')
    
# 1214
from sys import stdin
year, month=map(int, stdin.readline().split())

if month==2:
    if (year%400==0) or ((year%4==0)&(year%100!=0)):
        print(29)
    else:
        print(28)
elif month in [1,3,5,7,8,10,12]:
    print(31)
else:
    print(30)

# 1216
not_adv, adv, cost=map(int, input().split())
do_adv=adv-cost
if do_adv>not_adv:
    print('advertise')
elif do_adv<not_adv:
    print('do not advertise')
else:
    print('does not matter')


위와 같이 풀이하면 굳이 sorted 정렬 함수를 사용하지 않아도 풀이할 수 있다. 하지만, 나는 계속 Error가 뜬다...😡 왜 그런지는 잘 모르겠다..

# 1218
from sys import stdin
a,b,c=map(int, stdin.readline().split())
_list=[a,b,c]
_list=sorted(_list)

if _list[0]+_list[1]>_list[-1]:
    if _list[0]==_list[1]==_list[-1]:
        print('정삼각형')
    elif (_list[0]==_list[1])or(_list[1]==_list[-1]):
        print('이등변삼각형')
    elif _list[0]**2+_list[1]**2==_list[-1]**2:
        print('직각삼각형')
    else:
        print('삼각형')
else:
    print('삼각형아님')

📌 1226번, 1230번, 1231번 문제 풀이 실패

  • 1214번
    약간 이해가 안되는 점이 변수를 사용했을 때 자꾸 Error가 뜨는데 직접 연산을 적어주면 잘 돌아갔다...😡

  • 1226번: 이번 주 로또
    참고 블로그: 이번 주 로또1
    참고 블로그: 이번 주 로또2

💛 내가 풀이한 풀이~!

w1, w2, w3, w4, w5, w6, b=map(int, input().split())
l1, l2, l3, l4, l5, l6=map(int, input().split())

jihye_nums=[l1, l2, l3, l4, l5, l6]
lotto_nums=[w1, w2, w3, w4, w5, w6, b]

count=0
for num in jihye_nums:
    if num in lotto_nums:
        count+=1

bonus=False
if lotto_nums[-1] in jihye_nums:
    bonus=True
    
if (count==6) and (bonus=False):
    print(1)
elif (count==5) and (bonus=True):
    print(2)
elif (count==5) and (bonus=False):
    print(3)
elif (count==4) and (bonus=False):
    print(4)
elif (count==3) and (bonus=False):
    print(5)
else:
    print(0)
  • 1230번: 터널 통과하기.
    💛 내가 풀이한 풀이~!
    어디에 PASS 조건을 넣어줘야하는지 잘 모르겠다.
from sys import stdin
a,b,c=map(int, stdin.readline().split())
tunnel=[a,b,c]
height=170

for ii in tunnel:
    if ii<=height:
        print('CRASH', ii)
        break
    else:
        continue

💝 풀이에 성공한 1230번 문제 풀이 코드

from sys import stdin
a,b,c=map(int, stdin.readline().split())
tunnel=[a,b,c]
height=170

for ii in tunnel:
    if ii<=height:
        print('CRASH', ii)
        break
else:
    print('PASS')
  • 1231번: 계산기 만들기.
    💛 내가 풀이한 풀이~!
여기에 코드 적어주기

📌 오늘 내가 푼 문제 풀이 코드

# 1222
from sys import stdin
time, score1, score2=map(int, stdin.readline().split())

goal=0
while time<90:
    goal+=1
    time+=5
score1+=goal

if score1>score2:
    print('win')
elif score1<score2:
    print('lose')
else:
    print('same')
    
# 1224
from sys import stdin
a,b,c,d=map(int, stdin.readline().split())

if(a / b > c / d):
    print('>')
elif(a / b == c / d):
    print('=')
else:
    print('<')

# 1228
height, weight=map(float, input().split())
standard_weight=(height-100)*0.9
obesity=((weight-standard_weight)*100)/standard_weight

if obesity<=10:
    print('정상')
elif 10<obesity<=20:
    print('과체중')
else:
    print('비만')

# 1229
height, weight=map(float, input().split())

if height<150:
    standard_weight=height-100
elif 150<=height<160:
    standard_weight=(height-150)/2+50
else:
    standard_weight=(height-100)*0.9
    
obesity=((weight-standard_weight)*100)/standard_weight

if obesity<=10:
    print('정상')
elif 10<obesity<=20:
    print('과체중')
else:
    print('비만')

💛 2022. 01. 23. 일요일.

profile
알고리즘과 데이터 과학과 웹 개발을 공부하는 대학생

0개의 댓글