본문 바로가기

Python345

0115. Name on billboard You can print your name on a billboard ad. Find out how much it will cost you. Each character has a default price of £30, but that can be different if you are given 2 parameters instead of 1. You can not use multiplier "*" operator. If your name would be Jeong-Ho Aristotelis, ad would cost £600. 20 leters * 30 = 600 (Space counts as a character). Solution: def billboard(name, price=30): return s.. 2023. 1. 15.
0114. Are arrow functions odd? Time to test your basic knowledge in functions! Return the odds from a list: [1, 2, 3, 4, 5] --> [1, 3, 5] [2, 4, 6] --> [] Solution: odds = lambda x: [i for i in x if i & 1] 2023. 1. 15.
0113. Build a square I will give you an integer. Give me back a shape that is as long and wide as the integer. The integer will be a whole number between 1 and 50. Example n = 3, so I expect a 3x3 square back just like below as a string: +++ +++ +++ Solution: def generate_shape(n: int) -> str: return "\n".join("+" * n for i in range(n)) 2023. 1. 13.
0112. Tip Calculator Complete the function, which calculates how much you need to tip based on the total amount of the bill and the service. You need to consider the following ratings: Terrible: tip 0% Poor: tip 5% Good: tip 10% Great: tip 15% Excellent: tip 20% The rating is case insensitive (so "great" = "GREAT"). If an unrecognised rating is received, then you need to return: "Rating not recognised" in Javascript.. 2023. 1. 13.
0111. You Can't Code Under Pressure #1 Code as fast as you can! You need to double the integer and return it. Solution: def double_integer(i: int) -> int: try: return i ** 2 // (i / 2) except: return 0 def doubleInteger(i: int) -> int: return i 2023. 1. 12.
0110. altERnaTIng cAsE <=> ALTerNAtiNG CaSe altERnaTIng cAsE ALTerNAtiNG CaSe Define String.prototype.toAlternatingCase (or a similar function/method such as to_alternating_case/toAlternatingCase/ToAlternatingCase in your selected language; see the initial solution for details) such that each lowercase letter becomes uppercase and each uppercase letter becomes lowercase. For example: "hello world".toAlternatingCase() === "HELLO WORLD" "HE.. 2023. 1. 11.