백준 1330번 두수 비교하기
[파이썬/Python] 백준 1330번 두 수 비교하기
[파이썬/Python] 백준 1330번 두 수 비교하기
풀이a, b = map(int,input().split())if a > b: print('>')elif a
parkyongrok.tistory.com
기존 문제 풀이는 다음과 같다.
a, b = map(int,input().split())
if a > b:
print('>')
elif a < b:
print('<')
else:
print('==')
위의 문제를 다음과 같이 함수화 하였다
# 백준 1330번 두 수 비교하기
def compare_two_number(first_num, second_num):
if first_num > second_num:
return ">"
elif first_num < second_num:
return "<"
else:
return '=='
a, b = map(int,input().split())
print(compare_two_number(a,b))
백준 9498번 시험성적
[파이썬/Python] 백준 9498번 시험성적
풀이score = int(input())if score >= 90: grade = 'A'elif score >= 80: grade = 'B'elif score >= 70: grade = 'C'elif score >= 60: grade = 'D'else: grade = 'F' print(grade)
parkyongrok.tistory.com
기존 풀이는 다음과 같다
score = int(input())
if score >= 90:
grade = 'A'
elif score >= 80:
grade = 'B'
elif score >= 70:
grade = 'C'
elif score >= 60:
grade = 'D'
else:
grade = 'F'
print(grade)
위의 문제를 다음과 같이 함수화하였다.
# 백준 9498번 시험성적
def return_test_grade(score):
if score >= 90:
return 'A'
elif score >= 80:
return 'B'
elif score >= 70:
return 'C'
elif score >= 60:
return'D'
else:
return 'F'
score = int(input())
print(return_test_grade(score))
백준 2753번 윤년
[파이썬/Python] 백준 2753번 윤년
풀이year = int(input())if year%400==0: print(1)elif year%4==0 and not year%100==0: print(1)else: print(0)> 윤년이 되는 조건에 대해 잘 생각해 보아야 한다. 우선, 400의 배수인 해는 무조건적으로 윤년이므로 우선적으
parkyongrok.tistory.com
기존 풀이는 다음과 같다.
year = int(input())
if year%400==0:
print(1)
elif year%4==0 and not year%100==0:
print(1)
else:
print(0)
위의 문제를 다음과 같이 함수화 하였다.
# 백준 2753번 윤년
def is_leapyear(year):
if year%400==0:
return True
elif year%4==0 and not year%100==0:
return True
else:
return False
year = int(input())
print(is_leapyear(year))
백준 14681번 사분면 고르기
[파이썬/Python] 백준 14681번 사분면 고르기
[파이썬/Python] 백준 14681번 사분면 고르기
풀이x 좌표가 양수인지 음수인지 확인y 좌표가 양수인지 음수인지 확인해당하는 사분면 출력x = int(input())y = int(input())if x > 0 : if y > 0 : print(1) else: print(4)else: if y > 0: print(2) else: print(3)
parkyongrok.tistory.com
기존 풀이는 다음과 같다.
x = int(input())
y = int(input())
if x > 0 :
if y > 0 :
print(1)
else:
print(4)
else:
if y > 0:
print(2)
else:
print(3)
위의 문제를 다음과 같이 함수화 하였다.
# 백준 14681번 사분면 고르기
def return_quadrant(x, y):
if x > 0 :
if y > 0 :
return 1
else:
return 4
else:
if y > 0:
return 2
else:
return 3
x = int(input())
y = int(input())
print(return_quadrant(x,y))
백준 2884번 알람 시계
기존 풀이는 다음과 같다.
H, M = map(int, input().split())
if M-45 < 0:
H = (H-1)%24
M = (M-45)%60
else:
M = (M-45)%60
print(H,M)
위의 문제를 다음과 같이 함수화 하였다.
# 백준 2884번 알람 시계
def set_alarmclock(H,M):
if M-45 < 0:
H = (H-1)%24
M = (M-45)%60
else:
M = (M-45)%60
return H, M
Hour, Minute = map(int, input().split())
print(set_alarmclock(Hour, Minute))
백준 2525번 오븐 시계
[파이썬/Python] 백준 2525번 오븐 시계
풀이A, B = map(int,input().split())C = int(input())B += CA = A + (B//60)A = A % 24B = B % 60print(A,B)
parkyongrok.tistory.com
기존 풀이는 다음과 같다.
A, B = map(int,input().split())
C = int(input())
B += C
A = A + (B//60)
A = A % 24
B = B % 60
print(A,B)
위의 문제를 다음과 같이 함수화 하였다
# 백준 2525번 오븐 시계
def set_ovenclock(Hour, Minute, cooking_time):
Minute += cooking_time
Hour = Hour + (Minute//60)
return Hour % 24, Minute % 60
A, B = map(int,input().split())
C = int(input())
print(set_ovenclock(A, B, C))
백준 2480번 주사위
기존 풀이는 다음과 같다.
a, b, c = map(int,input().split())
if a == b == c :
print(10000+(a*1000))
elif a==b or b==c or a==c:
if a==b:
print(1000+(a*100))
elif b==c:
print(1000+(b*100))
else:
print(1000+(c*100))
else:
print(max(a,b,c)*100)
위 풀이를 다음과 같이 함수화 하였다
# 백준 2480번 주사위
def prize_dice(a ,b ,c):
if a == b == c :
return 10000+(a*1000)
elif a==b or b==c or a==c:
if a==b:
return 1000+(a*100)
elif b==c:
return 1000+(b*100)
else:
return 1000+(c*100)
else:
return max(a,b,c)*100
a, b, c = map(int,input().split())
print(prize_dice(a,b,c))
'[코테] Baekjoon 단계별 풀이 > 조건문' 카테고리의 다른 글
[파이썬/Python] 백준 2480번 주사위 (0) | 2024.06.28 |
---|---|
[파이썬/Python] 백준 2525번 오븐 시계 (0) | 2024.06.28 |
[파이썬/Python] 백준 2884번 알람 시계 (0) | 2024.06.28 |
[파이썬/Python] 백준 14681번 사분면 고르기 (0) | 2024.06.28 |
[파이썬/Python] 백준 2753번 윤년 (0) | 2024.06.28 |