Python345 0203. Parse float Write function parse_float which takes a string/list and returns a number or 'none' if conversion is not possible. Solution: def parse_float(string: str) -> float | None: try: return float(string) except (ValueError, TypeError): return None 2023. 2. 3. 0202. Beginner Series #1 School Paperwork Your classmates asked you to copy some paperwork for them. You know that there are 'n' classmates and the paperwork has 'm' pages. Your task is to calculate how many blank pages do you need. If n < 0 or m < 0 return 0. Example: n= 5, m=5: 25 n=-5, m=5: 0 Waiting for translations and Feedback! Thanks! Solution: def only_int(func): def wrapper(n, m): if n < 0 or m < 0: return 0 return func(n, m) r.. 2023. 2. 2. 0131. You only need one - Beginner You will be given an array a and a value x. All you need to do is check whether the provided array contains the value. Array can contain numbers or strings. X can be either. Return true if the array contains the value, false if not. Solution: check: bool = lambda x, y : y in x 2023. 2. 1. 0130. Grasshopper - Personalized Message Create a function that gives a personalized greeting. This function takes two parameters: name and owner. Use conditionals to return the proper message: case name equals owner : 'Hello boss' otherwise : 'Hello guest' Solution: def greet(name: str, owner: str) -> str: return f"Hello {name == owner and 'boss' or 'guest'}" 2023. 1. 31. 0129. Super Duper Easy Make a function that returns the value multiplied by 50 and increased by 6. If the value entered is a string it should return "Error". Solution: problem = lambda x: "Error" if isinstance(x, str) else x * 50 + 6 2023. 1. 29. 0128. Gauß needs help! (Sums of a lot of numbers). Due to another of his misbehaved, the primary school's teacher of the young Gauß, Herr J.G. Büttner, to keep the bored and unruly young schoolboy Karl Friedrich Gauss busy for a good long time, while he teaching arithmetic to his mates, assigned him the problem of adding up all the whole numbers from 1 through a given number n. Your task is to help the young Carl Friedrich to solve this problem .. 2023. 1. 28. 이전 1 2 3 4 5 6 7 8 ··· 58 다음