PYTHON/파이썬 코딩 도장
파이썬 코딩 도장 UNIT 33, 34, 35 심사문제
GaeGim
2022. 7. 30. 12:27
반응형
33.6 심사문제: 카운트다운 함수 만들기
def cntdwn(n):
cnt = n+1
def closure():
nonlocal cnt
cnt -= 1
return cnt
return closure
n = int(input())
c = cntdwn(n)
for i in range(n):
print(c(), end=' ')
34.6 심사문제: 게임 캐릭터 클래스 만들기
class Chrt:
def __init__(self,health,mana,ability_power):
self.health=health
self.mana=mana
self.ability_power=ability_power
def tibbers(self):
print('티버: 피해량 {0}'.format(self.ability_power*0.65+400))
health, mana, ability_power = map(float, input().split())
x = Chrt(health=health, mana=mana, ability_power=ability_power)
x.tibbers()
35.6 심사문제: 시간 클래스 만들기
class Time:
def __init__(self, hour, minute, second):
self.hour = hour
self.minute = minute
self.second = second
@classmethod
def from_string(cls,time_string):
hour, minute, second = map(int,time_string.split(':'))
time = cls(hour, minute, second)
return time
@staticmethod
def is_time_valid(time_string):
a,b,c = map(int,time_string.split(':'))
return a<=24 and b<=59 and c<=60
time_string = input()
if Time.is_time_valid(time_string):
t = Time.from_string(time_string)
print(t.hour, t.minute, t.second)
else:
print('잘못된 입력입니다.')
반응형