본문 바로가기

Python345

0830. Switch it Up! When provided with a number between 0-9, return it in words. Input :: 1 Output :: "One". Solution: def as_word(func): def wrapper(number, *args): ko_word = ["영", "일", "이", "삼", "사", "오", "육", "칠", "팔", "구"][number] en_word = ["Zero","One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"][number] return func(ko_word, en_word, *args) return wrapper @as_word def switch_it_up(ko_word.. 2022. 8. 30.
파이썬으로 해외 증권거래소 개장일/휴장일 확인하는 방법 덴마크 증권거래소는 몇 시에 열릴까? 국내 증권거래소의 정보는 손쉽게 구할 수 있다. 특히 개장일/휴장일의 경우 우리가 보는 달력만으로도 알 수 있다. 하지만 해외 증권거래소는 파악이 어렵다. 각 국가별로 공휴일이 다를 수 있고 시간도 상이하다. 특히 지역 시간대로 인해 정확한 시간을 파악하는 것이 더 어렵다. 덴마크 증권거래소를 예로 들어보겠다. 덴마크 장시작 시간이 몇 시인지 알고 있는가? 정답은 한국 시간으로 16시에 열린다.(이는 서머타임 시간이며 겨울에는 17시에 열린다.) 이미 본인에게 익숙한 시장이라면 어느 정도 파악해두고 있겠지만 그럼에도 각 국가별로 정확한 개장일과 개장시간을 파악하고 있는 것은 여간 성가신일이 아니다. 이러한 문제를 Python 라이브러리 exchange_calendar.. 2022. 8. 30.
0829. Holiday VIII - Duty Free The purpose of this kata is to work out just how many bottles of duty free whiskey you would have to buy such that the saving over the normal high street price would effectively cover the cost of your holiday. You will be given the high street price (normPrice), the duty free discount (discount) and the cost of the holiday. For example, if a bottle cost £10 normally and the discount in duty free.. 2022. 8. 29.
0828. Basic Mathematical Operations Your task is to create a function that does four basic mathematical operations. The function should take three arguments - operation(string/char), value1(number), value2(number). The function should return result of numbers after applying the chosen operation. Examples(Operator, value1, value2) --> output ('+', 4, 7) --> 11 ('-', 15, 18) --> -3 ('*', 5, 5) --> 25 ('/', 49, 7) --> 7 Solution: def.. 2022. 8. 28.
Tenacity _ 예외가 발생한 함수를 다시 실행하려면? Tenacity 란? 보통 에러나 예외처리에 의해 런타임이 종료될 때가 있다. Tenacity는 런타임 종료없이 함수를 다시 실행시켜주는 Python 라이브러리이다. 사용법 1. Tenacity 설치 pip install tenacity 2. Tenacity 라이브러리 가져오기 및 함수 작성 import tenacity def throw_error(): print("running...") raise ValueError("Errors make me stronger") if __name__ == "__main__": throw_error() 이대로 스크립트를 실행해보면 우리가 의도한대로 에러가 발생하며 곧바로 스크립트가 종료된다. running... Traceback (most recent call last.. 2022. 8. 27.
0827. Sum Arrays Write a function that takes an array of numbers and returns the sum of the numbers. The numbers can be negative or non-integer. If the array does not contain any numbers then you should return 0. Examples Input: [1, 5.2, 4, 0, -1] Output: 9.2 Input: [] Output: 0 Input: [-2.398] Output: -2.398 Assumptions You can assume that you are only given numbers. You cannot assume the size of the array. You.. 2022. 8. 27.