본문 바로가기

Python345

1010. Double Char Given a string, you have to return a string in which each character (case-sensitive) is repeated once. Examples (Input -> Output): * "String" -> "SSttrriinngg" * "Hello World" -> "HHeelllloo WWoorrlldd" * "1234!_ " -> "11223344!!__ " Good Luck! Solution: def double_char(s: str) -> str: return "".join((lambda x: x+x)(i) for i in s) 2022. 10. 10.
1009. Surface Area and Volume of a Box Write a function that returns the total surface area and volume of a box as an array: [area, volume] Solution: def get_size(w,h,d): wh = w*h*2 hd = h*d*2 wd = w*d*2 return [wh+hd+wd, w*h*d] 2022. 10. 10.
1008. Drink about Kids drink toddy. Teens drink coke. Young adults drink beer. Adults drink whisky. Make a function that receive age, and return what they drink. Rules: Children under 14 old. Teens under 18 old. Young under 21 old. Adults have 21 or more. Examples: (Input --> Output) 13 --> "drink toddy" 17 --> "drink coke" 18 --> "drink beer" 20 --> "drink beer" 30 --> "drink whisky" Solution: DRINKS = { "Childr.. 2022. 10. 8.
1007. Volume of a Cuboid Bob needs a fast way to calculate the volume of a cuboid with three values: the length, width and height of the cuboid. Write a function to help Bob with this calculation. Solution: from typing import List, Callable def get_multiply(args: List[int], result:int = 1) -> int: for i in args: result *= i return result def get_volume_of_cuboid(length: int, width: int, height: int, func: Callable = get.. 2022. 10. 8.
1006. Filter out the geese Write a function that takes a list of strings as an argument and returns a filtered list containing the same elements but with the 'geese' removed. The geese are any strings in the following array, which is pre-populated in your solution: ["African", "Roman Tufted", "Toulouse", "Pilgrim", "Steinbacher"] For example, if this array were passed as an argument: ["Mallard", "Hook Bill", "African", "C.. 2022. 10. 6.
1005. Palindrome Strings Palindrome strings A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. This includes capital letters, punctuation, and word dividers. Implement a function that checks if something is a palindrome. If the input is a number, convert it to string first. Examples(Input ==> Output) "anna" ==> true "walter" ==> false 12321 ==> true 123456 =.. 2022. 10. 5.