본문 바로가기

and19

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.
0826. A wolf in sheep's clothing Wolves have been reintroduced to Great Britain. You are a sheep farmer, and are now plagued by wolves which pretend to be sheep. Fortunately, you are good at spotting them. Warn the sheep in front of the wolf that it is about to be eaten. Remember that you are standing at the front of the queue which is at the end of the array: [sheep, sheep, sheep, sheep, sheep, wolf, sheep, sheep] (YOU ARE HER.. 2022. 8. 26.
Maximum subarray sum The maximum sum subarray problem consists in finding the maximum sum of a contiguous subsequence in an array or list of integers: max_sequence([-2, 1, -3, 4, -1, 2, 1, -5, 4]) # should be 6: [4, -1, 2, 1] Easy case is when the list is made up of only positive numbers and the maximum sum is the sum of the whole array. If the list is made up of only negative numbers, return 0 instead. Empty list i.. 2022. 8. 12.
Make a function that does arithmetic! Given two numbers and an arithmetic operator (the name of it, as a string), return the result of the two numbers having that operator used on them. a and b will both be positive integers, and a will always be the first number in the operation, and b always the second. The four operators are "add", "subtract", "divide", "multiply". A few examples:(Input1, Input2, Input3 --> Output) 5, 2, "add" --.. 2022. 7. 31.
Build Tower Build Tower Build a pyramid-shaped tower given a positive integer number of floors. A tower block is represented with "*" character. For example, a tower with 3 floors looks like this: [ " * ", " *** ", "*****" ] And a tower with 6 floors looks like this: [ " * ", " *** ", " ***** ", " ******* ", " ********* ", "***********" ] Solution: def tower_builder(n_floors): nums = [i>0 and i*2+1 or 1 for.. 2022. 7. 29.
Calculate BMI Write function bmi that calculates body mass index (bmi = weight / height2). if bmi 25 and "Overweight") \ or (bmi > 18.5 and "Normal") \ or "Underweight" 2022. 7. 25.