본문 바로가기

Python345

0916. Do you speak "English"? Given a string of arbitrary length with any ascii characters. Write a function to determine whether the string contains the whole word "English". The order of characters is important -- a string "abcEnglishdef" is correct but "abcnEglishsef" is not correct. Upper or lower case letter does not matter -- "eNglisH" is also correct. Return value as boolean values, true for the string to contains "En.. 2022. 9. 16.
0915. Beginner - Reduce but Grow Given a non-empty array of integers, return the result of multiplying the values together in order. Example: [1, 2, 3, 4] => 1 * 2 * 3 * 4 = 24 Solution: def grow(arr, i=1): return grow(arr, i*arr.pop()) if arr else i 2022. 9. 15.
0914. Rock Paper Scissors! Rock Paper Scissors Let's play! You have to return which player won! In case of a draw return Draw!. Examples(Input1, Input2 --> Output): "scissors", "paper" --> "Player 1 won!" "scissors", "rock" --> "Player 2 won!" "paper", "paper" --> "Draw!" Solution: from typing import Dict def check_draw(func): def wrapper(p1, p2): table = {"s":"p","r":"s","p":"r"} return p1 == p2 and "Draw!" or func(p1, p.. 2022. 9. 14.
0913. Take the Derivative This function takes two numbers as parameters, the first number being the coefficient, and the second number being the exponent. Your function should multiply the two numbers, and then subtract 1 from the exponent. Then, it has to print out an expression (like 28x^7). "^1" should not be truncated when exponent = 2. For example: derive(7, 8) In this case, the function should multiply 7 and 8, and.. 2022. 9. 13.
0912. Fake Binary Given a string of digits, you should replace any digit below 5 with '0' and any digit 5 and above with '1'. Return the resulting string. Note: input will never be an empty string Solution: def fake_bin(x): return ''.join(str(int(i) >= 5 and 1 or 0) for i in x) 2022. 9. 13.
0911. Add Length What if we need the length of the words separated by a space to be added at the end of that same word and have it returned as an array? Example(Input --> Output) "apple ban" --> ["apple 5", "ban 3"] "you will win" -->["you 3", "will 4", "win 3"] Your task is to write a function that takes a String and returns an Array/list with the length of each word added to each element . Note: String will ha.. 2022. 9. 11.