Datasets:

inputs
stringlengths
50
14k
targets
stringlengths
4
655k
This series of katas will introduce you to basics of doing geometry with computers. `Point` objects have `x`, `y`, and `z` attributes. For Haskell there are `Point` data types described with record syntax with fields `x`, `y`, and `z`. Write a function calculating distance between `Point a` and `Point b`. Tests round answers to 6 decimal places. Tests in Haskell will not round.
def distance_between_points(a, b): ss = [(a.__getattribute__(i) - b.__getattribute__(i))**2 for i in 'xyz'] return (sum(ss))**0.5
A traveling salesman has to visit clients. He got each client's address e.g. `"432 Main Long Road St. Louisville OH 43071"` as a list. The basic zipcode format usually consists of two capital letters followed by a white space and five digits. The list of clients to visit was given as a string of all addresses, each separated from the others by a comma, e.g. : `"123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432"`. To ease his travel he wants to group the list by zipcode. # Task The function `travel` will take two parameters `r` (addresses' list of all clients' as a string) and `zipcode` and returns a string in the following format: `zipcode:street and town,street and town,.../house number,house number,...` The street numbers must be in the same order as the streets where they belong. If a given zipcode doesn't exist in the list of clients' addresses return `"zipcode:/"` # Examples ``` r = "123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432" travel(r, "OH 43071") --> "OH 43071:Main Street St. Louisville,Main Long Road St. Louisville/123,432" travel(r, "NY 56432") --> "NY 56432:High Street Pollocksville/786" travel(r, "NY 5643") --> "NY 5643:/" ``` # Note for Elixir: In Elixir the empty addresses' input is an empty *list*, not an empty string. # Note: You can see a few addresses and zipcodes in the test cases.
def travel(r, zipcode): streets = [] nums = [] addresses = r.split(',') for address in addresses: if ' '.join(address.split()[-2:]) == zipcode: streets.append(' '.join(address.split()[1:-2])) nums += address.split()[:1] return '{}:{}/{}'.format(zipcode, ','.join(streets), ','.join(nums))
A traveling salesman has to visit clients. He got each client's address e.g. `"432 Main Long Road St. Louisville OH 43071"` as a list. The basic zipcode format usually consists of two capital letters followed by a white space and five digits. The list of clients to visit was given as a string of all addresses, each separated from the others by a comma, e.g. : `"123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432"`. To ease his travel he wants to group the list by zipcode. # Task The function `travel` will take two parameters `r` (addresses' list of all clients' as a string) and `zipcode` and returns a string in the following format: `zipcode:street and town,street and town,.../house number,house number,...` The street numbers must be in the same order as the streets where they belong. If a given zipcode doesn't exist in the list of clients' addresses return `"zipcode:/"` # Examples ``` r = "123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432" travel(r, "OH 43071") --> "OH 43071:Main Street St. Louisville,Main Long Road St. Louisville/123,432" travel(r, "NY 56432") --> "NY 56432:High Street Pollocksville/786" travel(r, "NY 5643") --> "NY 5643:/" ``` # Note for Elixir: In Elixir the empty addresses' input is an empty *list*, not an empty string. # Note: You can see a few addresses and zipcodes in the test cases.
import re def travel(r, zipcode): res = [(m.group(2), m.group(1)) for m in re.finditer(r'(\d+) ([^,]+) ([A-Z][A-Z] \d{5})', r) if zipcode == m.group(3)] return '{}:{}/{}'.format(zipcode, ','.join(a[0] for a in res), ','.join(a[1] for a in res))
A traveling salesman has to visit clients. He got each client's address e.g. `"432 Main Long Road St. Louisville OH 43071"` as a list. The basic zipcode format usually consists of two capital letters followed by a white space and five digits. The list of clients to visit was given as a string of all addresses, each separated from the others by a comma, e.g. : `"123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432"`. To ease his travel he wants to group the list by zipcode. # Task The function `travel` will take two parameters `r` (addresses' list of all clients' as a string) and `zipcode` and returns a string in the following format: `zipcode:street and town,street and town,.../house number,house number,...` The street numbers must be in the same order as the streets where they belong. If a given zipcode doesn't exist in the list of clients' addresses return `"zipcode:/"` # Examples ``` r = "123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432" travel(r, "OH 43071") --> "OH 43071:Main Street St. Louisville,Main Long Road St. Louisville/123,432" travel(r, "NY 56432") --> "NY 56432:High Street Pollocksville/786" travel(r, "NY 5643") --> "NY 5643:/" ``` # Note for Elixir: In Elixir the empty addresses' input is an empty *list*, not an empty string. # Note: You can see a few addresses and zipcodes in the test cases.
from collections import defaultdict from re import compile, match REGEX = compile(r'(?P<num>\d+) (?P<adr>.+) (?P<st_zip>[A-Z]{2} \d{5})') def travel(addresses, zipcode): by_zipcode = defaultdict(lambda: defaultdict(list)) for address in addresses.split(','): m = match(REGEX, address).groupdict() by_zipcode[m['st_zip']]['adr'].append(m['adr']) by_zipcode[m['st_zip']]['num'].append(m['num']) result = by_zipcode[zipcode] return '{}:{}/{}'\ .format(zipcode, ','.join(result['adr']), ','.join(result['num']))
A traveling salesman has to visit clients. He got each client's address e.g. `"432 Main Long Road St. Louisville OH 43071"` as a list. The basic zipcode format usually consists of two capital letters followed by a white space and five digits. The list of clients to visit was given as a string of all addresses, each separated from the others by a comma, e.g. : `"123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432"`. To ease his travel he wants to group the list by zipcode. # Task The function `travel` will take two parameters `r` (addresses' list of all clients' as a string) and `zipcode` and returns a string in the following format: `zipcode:street and town,street and town,.../house number,house number,...` The street numbers must be in the same order as the streets where they belong. If a given zipcode doesn't exist in the list of clients' addresses return `"zipcode:/"` # Examples ``` r = "123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432" travel(r, "OH 43071") --> "OH 43071:Main Street St. Louisville,Main Long Road St. Louisville/123,432" travel(r, "NY 56432") --> "NY 56432:High Street Pollocksville/786" travel(r, "NY 5643") --> "NY 5643:/" ``` # Note for Elixir: In Elixir the empty addresses' input is an empty *list*, not an empty string. # Note: You can see a few addresses and zipcodes in the test cases.
import re def travel(r, zipcode): addresses = [address for address in r.split(',') if re.match('\d+ .+ {}$'.format(zipcode),address)] streets = [] houses = [] for address in addresses: house, street = re.findall('(\d+) (.+) .* .*',address)[0] streets.append(street) houses.append(house) return zipcode + ':' + ','.join(streets) + '/' + ','.join(houses)
A traveling salesman has to visit clients. He got each client's address e.g. `"432 Main Long Road St. Louisville OH 43071"` as a list. The basic zipcode format usually consists of two capital letters followed by a white space and five digits. The list of clients to visit was given as a string of all addresses, each separated from the others by a comma, e.g. : `"123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432"`. To ease his travel he wants to group the list by zipcode. # Task The function `travel` will take two parameters `r` (addresses' list of all clients' as a string) and `zipcode` and returns a string in the following format: `zipcode:street and town,street and town,.../house number,house number,...` The street numbers must be in the same order as the streets where they belong. If a given zipcode doesn't exist in the list of clients' addresses return `"zipcode:/"` # Examples ``` r = "123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432" travel(r, "OH 43071") --> "OH 43071:Main Street St. Louisville,Main Long Road St. Louisville/123,432" travel(r, "NY 56432") --> "NY 56432:High Street Pollocksville/786" travel(r, "NY 5643") --> "NY 5643:/" ``` # Note for Elixir: In Elixir the empty addresses' input is an empty *list*, not an empty string. # Note: You can see a few addresses and zipcodes in the test cases.
def travel(r, zipcode): out = [[],[]] endstr = zipcode + ':' r = r.split(',') for data in r: if data[len(data)-8:] == zipcode: strt = data.split(' ', 1)[1][:-9] apt = data.split(' ', 1)[0] out[0].append(strt) out[1].append(apt) endstr += ','.join(out[0]) + '/' endstr += ','.join(out[1]) return endstr
A traveling salesman has to visit clients. He got each client's address e.g. `"432 Main Long Road St. Louisville OH 43071"` as a list. The basic zipcode format usually consists of two capital letters followed by a white space and five digits. The list of clients to visit was given as a string of all addresses, each separated from the others by a comma, e.g. : `"123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432"`. To ease his travel he wants to group the list by zipcode. # Task The function `travel` will take two parameters `r` (addresses' list of all clients' as a string) and `zipcode` and returns a string in the following format: `zipcode:street and town,street and town,.../house number,house number,...` The street numbers must be in the same order as the streets where they belong. If a given zipcode doesn't exist in the list of clients' addresses return `"zipcode:/"` # Examples ``` r = "123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432" travel(r, "OH 43071") --> "OH 43071:Main Street St. Louisville,Main Long Road St. Louisville/123,432" travel(r, "NY 56432") --> "NY 56432:High Street Pollocksville/786" travel(r, "NY 5643") --> "NY 5643:/" ``` # Note for Elixir: In Elixir the empty addresses' input is an empty *list*, not an empty string. # Note: You can see a few addresses and zipcodes in the test cases.
def travel(r, zipcode): return zipcode + ':' + ','.join([' '.join(x.split()[1:]) for x in [x[:-9] for x in r.split(',') if x[-8:] == zipcode]]) + '/' + ','.join([x.split()[0] for x in [x[:-9] for x in r.split(',') if x[-8:] == zipcode]])
A traveling salesman has to visit clients. He got each client's address e.g. `"432 Main Long Road St. Louisville OH 43071"` as a list. The basic zipcode format usually consists of two capital letters followed by a white space and five digits. The list of clients to visit was given as a string of all addresses, each separated from the others by a comma, e.g. : `"123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432"`. To ease his travel he wants to group the list by zipcode. # Task The function `travel` will take two parameters `r` (addresses' list of all clients' as a string) and `zipcode` and returns a string in the following format: `zipcode:street and town,street and town,.../house number,house number,...` The street numbers must be in the same order as the streets where they belong. If a given zipcode doesn't exist in the list of clients' addresses return `"zipcode:/"` # Examples ``` r = "123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432" travel(r, "OH 43071") --> "OH 43071:Main Street St. Louisville,Main Long Road St. Louisville/123,432" travel(r, "NY 56432") --> "NY 56432:High Street Pollocksville/786" travel(r, "NY 5643") --> "NY 5643:/" ``` # Note for Elixir: In Elixir the empty addresses' input is an empty *list*, not an empty string. # Note: You can see a few addresses and zipcodes in the test cases.
def travel(r, zipcode): matches = [' '.join(i.split()[:-2]) for i in r.split(',') if (' '.join(i.split()[-2:]) == zipcode)] return "%s:" % zipcode + ','.join([' '.join(i.split()[1:]) for i in matches])+'/'+','.join([''.join(i.split()[:1]) for i in matches])
A traveling salesman has to visit clients. He got each client's address e.g. `"432 Main Long Road St. Louisville OH 43071"` as a list. The basic zipcode format usually consists of two capital letters followed by a white space and five digits. The list of clients to visit was given as a string of all addresses, each separated from the others by a comma, e.g. : `"123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432"`. To ease his travel he wants to group the list by zipcode. # Task The function `travel` will take two parameters `r` (addresses' list of all clients' as a string) and `zipcode` and returns a string in the following format: `zipcode:street and town,street and town,.../house number,house number,...` The street numbers must be in the same order as the streets where they belong. If a given zipcode doesn't exist in the list of clients' addresses return `"zipcode:/"` # Examples ``` r = "123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432" travel(r, "OH 43071") --> "OH 43071:Main Street St. Louisville,Main Long Road St. Louisville/123,432" travel(r, "NY 56432") --> "NY 56432:High Street Pollocksville/786" travel(r, "NY 5643") --> "NY 5643:/" ``` # Note for Elixir: In Elixir the empty addresses' input is an empty *list*, not an empty string. # Note: You can see a few addresses and zipcodes in the test cases.
import re def travel(r, zipcode): r = r.split(',') filtered = [*filter(lambda x: re.search(f"{zipcode}$", x), r)] nums, streets = [], [] for address in filtered: num, street = address.split(' ', 1) nums.append(num) streets.append(street.rstrip(' ' + zipcode)) return filtered != [] and zipcode and \ f"{zipcode}:{','.join(streets)}/{','.join(nums)}" or f"{zipcode}:/"
A traveling salesman has to visit clients. He got each client's address e.g. `"432 Main Long Road St. Louisville OH 43071"` as a list. The basic zipcode format usually consists of two capital letters followed by a white space and five digits. The list of clients to visit was given as a string of all addresses, each separated from the others by a comma, e.g. : `"123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432"`. To ease his travel he wants to group the list by zipcode. # Task The function `travel` will take two parameters `r` (addresses' list of all clients' as a string) and `zipcode` and returns a string in the following format: `zipcode:street and town,street and town,.../house number,house number,...` The street numbers must be in the same order as the streets where they belong. If a given zipcode doesn't exist in the list of clients' addresses return `"zipcode:/"` # Examples ``` r = "123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432" travel(r, "OH 43071") --> "OH 43071:Main Street St. Louisville,Main Long Road St. Louisville/123,432" travel(r, "NY 56432") --> "NY 56432:High Street Pollocksville/786" travel(r, "NY 5643") --> "NY 5643:/" ``` # Note for Elixir: In Elixir the empty addresses' input is an empty *list*, not an empty string. # Note: You can see a few addresses and zipcodes in the test cases.
def travel(r: str, zipcode: str) -> str: addresses, numbers = [], [] if zipcode: for a in r.split(','): s, _, rem = a.rpartition(zipcode) if s and not rem: n, a = s[:-1].split(maxsplit=1) numbers.append(n) addresses.append(a) return f"{zipcode}:{','.join(addresses)}/{','.join(numbers)}"
A traveling salesman has to visit clients. He got each client's address e.g. `"432 Main Long Road St. Louisville OH 43071"` as a list. The basic zipcode format usually consists of two capital letters followed by a white space and five digits. The list of clients to visit was given as a string of all addresses, each separated from the others by a comma, e.g. : `"123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432"`. To ease his travel he wants to group the list by zipcode. # Task The function `travel` will take two parameters `r` (addresses' list of all clients' as a string) and `zipcode` and returns a string in the following format: `zipcode:street and town,street and town,.../house number,house number,...` The street numbers must be in the same order as the streets where they belong. If a given zipcode doesn't exist in the list of clients' addresses return `"zipcode:/"` # Examples ``` r = "123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432" travel(r, "OH 43071") --> "OH 43071:Main Street St. Louisville,Main Long Road St. Louisville/123,432" travel(r, "NY 56432") --> "NY 56432:High Street Pollocksville/786" travel(r, "NY 5643") --> "NY 5643:/" ``` # Note for Elixir: In Elixir the empty addresses' input is an empty *list*, not an empty string. # Note: You can see a few addresses and zipcodes in the test cases.
import re def travel(r, zipcode): addresses = [*[x for x in r.split(",") if re.findall(r"[A-Z]{2} \d{5}", x)[0] == zipcode]] if not addresses: return f"{zipcode}:/" numbers = [] for i, a in enumerate(addresses): n = re.findall(r"\d{1,5}(?= \w+)", a)[0] numbers.append(n) addresses[i] = a.strip(n).strip(zipcode) return f"{zipcode}:{','.join(addresses)}/{','.join(numbers)}"
You need to create a function that will validate if given parameters are valid geographical coordinates. Valid coordinates look like the following: __"23.32353342, -32.543534534"__. The return value should be either __true__ or __false__. Latitude (which is first float) can be between 0 and 90, positive or negative. Longitude (which is second float) can be between 0 and 180, positive or negative. Coordinates can only contain digits, or one of the following symbols (including space after comma) __ -, . __ There should be no space between the minus "-" sign and the digit after it. Here are some valid coordinates: * -23, 25 * 24.53525235, 23.45235 * 04, -23.234235 * 43.91343345, 143 * 4, -3 And some invalid ones: * 23.234, - 23.4234 * 2342.43536, 34.324236 * N23.43345, E32.6457 * 99.234, 12.324 * 6.325624, 43.34345.345 * 0, 1,2 * 0.342q0832, 1.2324
def is_valid_coordinates(coordinates): try: lat, lng = [abs(float(c)) for c in coordinates.split(',') if 'e' not in c] except ValueError: return False return lat <= 90 and lng <= 180
You need to create a function that will validate if given parameters are valid geographical coordinates. Valid coordinates look like the following: __"23.32353342, -32.543534534"__. The return value should be either __true__ or __false__. Latitude (which is first float) can be between 0 and 90, positive or negative. Longitude (which is second float) can be between 0 and 180, positive or negative. Coordinates can only contain digits, or one of the following symbols (including space after comma) __ -, . __ There should be no space between the minus "-" sign and the digit after it. Here are some valid coordinates: * -23, 25 * 24.53525235, 23.45235 * 04, -23.234235 * 43.91343345, 143 * 4, -3 And some invalid ones: * 23.234, - 23.4234 * 2342.43536, 34.324236 * N23.43345, E32.6457 * 99.234, 12.324 * 6.325624, 43.34345.345 * 0, 1,2 * 0.342q0832, 1.2324
import re def is_valid_coordinates(coordinates): return bool(re.match("-?(\d|[1-8]\d|90)\.?\d*, -?(\d|[1-9]\d|1[0-7]\d|180)\.?\d*$", coordinates))
You need to create a function that will validate if given parameters are valid geographical coordinates. Valid coordinates look like the following: __"23.32353342, -32.543534534"__. The return value should be either __true__ or __false__. Latitude (which is first float) can be between 0 and 90, positive or negative. Longitude (which is second float) can be between 0 and 180, positive or negative. Coordinates can only contain digits, or one of the following symbols (including space after comma) __ -, . __ There should be no space between the minus "-" sign and the digit after it. Here are some valid coordinates: * -23, 25 * 24.53525235, 23.45235 * 04, -23.234235 * 43.91343345, 143 * 4, -3 And some invalid ones: * 23.234, - 23.4234 * 2342.43536, 34.324236 * N23.43345, E32.6457 * 99.234, 12.324 * 6.325624, 43.34345.345 * 0, 1,2 * 0.342q0832, 1.2324
def is_valid_coordinates(s): try: a, b = s.split(',') if 'e' in a or 'e' in b: raise Exception a, b = float(a), float(b) return abs(a)<=90 and abs(b)<=180 except: return False
You need to create a function that will validate if given parameters are valid geographical coordinates. Valid coordinates look like the following: __"23.32353342, -32.543534534"__. The return value should be either __true__ or __false__. Latitude (which is first float) can be between 0 and 90, positive or negative. Longitude (which is second float) can be between 0 and 180, positive or negative. Coordinates can only contain digits, or one of the following symbols (including space after comma) __ -, . __ There should be no space between the minus "-" sign and the digit after it. Here are some valid coordinates: * -23, 25 * 24.53525235, 23.45235 * 04, -23.234235 * 43.91343345, 143 * 4, -3 And some invalid ones: * 23.234, - 23.4234 * 2342.43536, 34.324236 * N23.43345, E32.6457 * 99.234, 12.324 * 6.325624, 43.34345.345 * 0, 1,2 * 0.342q0832, 1.2324
import re COORD_RE = re.compile(r'(-?[\d]+\.?[\d]*), ?(-?[\d]+\.?[\d]*)$') def is_valid_coordinates(coordinates): match = COORD_RE.match(coordinates) if not match: return False x, y = match.group(1), match.group(2) x, y = float(x), float(y) if not 0 <= abs(x) <= 90: return False if not 0 <= abs(y) <= 180: return False return True
You need to create a function that will validate if given parameters are valid geographical coordinates. Valid coordinates look like the following: __"23.32353342, -32.543534534"__. The return value should be either __true__ or __false__. Latitude (which is first float) can be between 0 and 90, positive or negative. Longitude (which is second float) can be between 0 and 180, positive or negative. Coordinates can only contain digits, or one of the following symbols (including space after comma) __ -, . __ There should be no space between the minus "-" sign and the digit after it. Here are some valid coordinates: * -23, 25 * 24.53525235, 23.45235 * 04, -23.234235 * 43.91343345, 143 * 4, -3 And some invalid ones: * 23.234, - 23.4234 * 2342.43536, 34.324236 * N23.43345, E32.6457 * 99.234, 12.324 * 6.325624, 43.34345.345 * 0, 1,2 * 0.342q0832, 1.2324
def is_valid_coordinates(coordinates): print(coordinates) for char in coordinates: if not (char.isdigit() or char in ['-', '.', ',', ' ']): return False l = coordinates.split(", ") if len(l) != 2: return False print(l) try: latitude = float(l[0]) longitude = float(l[1]) except: return False print(latitude, longitude) return -90 <= latitude <= 90 and -180 <= longitude <= 180
You need to create a function that will validate if given parameters are valid geographical coordinates. Valid coordinates look like the following: __"23.32353342, -32.543534534"__. The return value should be either __true__ or __false__. Latitude (which is first float) can be between 0 and 90, positive or negative. Longitude (which is second float) can be between 0 and 180, positive or negative. Coordinates can only contain digits, or one of the following symbols (including space after comma) __ -, . __ There should be no space between the minus "-" sign and the digit after it. Here are some valid coordinates: * -23, 25 * 24.53525235, 23.45235 * 04, -23.234235 * 43.91343345, 143 * 4, -3 And some invalid ones: * 23.234, - 23.4234 * 2342.43536, 34.324236 * N23.43345, E32.6457 * 99.234, 12.324 * 6.325624, 43.34345.345 * 0, 1,2 * 0.342q0832, 1.2324
def is_valid_coordinates(coordinates): coords = coordinates.split(',') if len(coords) != 2 or 'e' in coordinates: return False for i,coord in enumerate(coords): try: coord = float(coord) if (i == 0 and abs(coord) > 90) or (i == 1 and abs(coord) > 180): return False except: return False return True
You need to create a function that will validate if given parameters are valid geographical coordinates. Valid coordinates look like the following: __"23.32353342, -32.543534534"__. The return value should be either __true__ or __false__. Latitude (which is first float) can be between 0 and 90, positive or negative. Longitude (which is second float) can be between 0 and 180, positive or negative. Coordinates can only contain digits, or one of the following symbols (including space after comma) __ -, . __ There should be no space between the minus "-" sign and the digit after it. Here are some valid coordinates: * -23, 25 * 24.53525235, 23.45235 * 04, -23.234235 * 43.91343345, 143 * 4, -3 And some invalid ones: * 23.234, - 23.4234 * 2342.43536, 34.324236 * N23.43345, E32.6457 * 99.234, 12.324 * 6.325624, 43.34345.345 * 0, 1,2 * 0.342q0832, 1.2324
def is_valid_coordinates(coordinates): # all characters to be used digits = ["1","2","3","4","5","6","7","8","9","0"] dec = "." comma = "," space = " " neg = "-" # counters negOK, digitOK = True, True decOK, spaceOK, commaOK = False, False, False hitComma = False hitDec = False for c in coordinates: print(c) if hitComma: commaOK = False if c in digits: if not digitOK: return False if not hitDec: decOK = True commaOK = True negOK = False continue elif c == neg: if not negOK: return False negOK, commaOK, decOK, spaceOK = False, False, False, False continue elif c == dec: if not decOK: return False negOK, commaOK, decOK, spaceOK = False, False, False, False digitOK = True hitDec = True continue elif c == comma: if not commaOK: return False negOK, commaOK, decOK, digitOK = False, False, False, False spaceOK = True continue elif c == space: if not spaceOK: return False negOK, digitOK = True, True decOK, spaceOK, commaOK = False, False, False hitComma = True hitDec = False continue return False # now check the size of the coordinates cArr = coordinates.split(", ") if abs(float(cArr[0])) > 90 or abs(float(cArr[1])) > 180: return False return True
You need to create a function that will validate if given parameters are valid geographical coordinates. Valid coordinates look like the following: __"23.32353342, -32.543534534"__. The return value should be either __true__ or __false__. Latitude (which is first float) can be between 0 and 90, positive or negative. Longitude (which is second float) can be between 0 and 180, positive or negative. Coordinates can only contain digits, or one of the following symbols (including space after comma) __ -, . __ There should be no space between the minus "-" sign and the digit after it. Here are some valid coordinates: * -23, 25 * 24.53525235, 23.45235 * 04, -23.234235 * 43.91343345, 143 * 4, -3 And some invalid ones: * 23.234, - 23.4234 * 2342.43536, 34.324236 * N23.43345, E32.6457 * 99.234, 12.324 * 6.325624, 43.34345.345 * 0, 1,2 * 0.342q0832, 1.2324
def is_valid_coordinates(coordinates): x = coordinates.split(', ') try: if len(x) == 2 and 90 >= float(x[0]) >= -90 and 180 >= float(x[1]) >= -180 and not any(c.isalpha() for c in x[0]) and not any(c.isalpha() for c in x[1]): return True except: return False return False
You need to create a function that will validate if given parameters are valid geographical coordinates. Valid coordinates look like the following: __"23.32353342, -32.543534534"__. The return value should be either __true__ or __false__. Latitude (which is first float) can be between 0 and 90, positive or negative. Longitude (which is second float) can be between 0 and 180, positive or negative. Coordinates can only contain digits, or one of the following symbols (including space after comma) __ -, . __ There should be no space between the minus "-" sign and the digit after it. Here are some valid coordinates: * -23, 25 * 24.53525235, 23.45235 * 04, -23.234235 * 43.91343345, 143 * 4, -3 And some invalid ones: * 23.234, - 23.4234 * 2342.43536, 34.324236 * N23.43345, E32.6457 * 99.234, 12.324 * 6.325624, 43.34345.345 * 0, 1,2 * 0.342q0832, 1.2324
def is_valid_coordinates(c): try: return all(-r <= float(s) <= r and 'e' not in s for s,r in zip(c.split(','), [90,180,-1])) except ValueError: return False
You need to create a function that will validate if given parameters are valid geographical coordinates. Valid coordinates look like the following: __"23.32353342, -32.543534534"__. The return value should be either __true__ or __false__. Latitude (which is first float) can be between 0 and 90, positive or negative. Longitude (which is second float) can be between 0 and 180, positive or negative. Coordinates can only contain digits, or one of the following symbols (including space after comma) __ -, . __ There should be no space between the minus "-" sign and the digit after it. Here are some valid coordinates: * -23, 25 * 24.53525235, 23.45235 * 04, -23.234235 * 43.91343345, 143 * 4, -3 And some invalid ones: * 23.234, - 23.4234 * 2342.43536, 34.324236 * N23.43345, E32.6457 * 99.234, 12.324 * 6.325624, 43.34345.345 * 0, 1,2 * 0.342q0832, 1.2324
def is_valid_coordinates(coordinates): valid_chars = set('0123456789-.') try: latitude, longitude = (abs(float(a)) for a in coordinates.split(', ') if valid_chars.issuperset(a)) except ValueError: return False return latitude <= 90 and longitude <= 180
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=''): return f"Hello, {name.title() or 'World'}!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=""): return f"Hello, {name.capitalize() if name else 'World'}!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=None): if not name: return "Hello, World!" return "Hello, %s!"%(name.capitalize())
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=''): return "Hello, {}!".format(name.title() if name else 'World')
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
hello = lambda name="": "Hello, {}!".format("World" if not name else name.capitalize())
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=''): return "Hello, %s!" % ['World',name.title()][name!='']
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name='World'): return 'Hello, {}!'.format(name.capitalize() if name else 'World')
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=''): return f"hello, {name or 'world'}!".title()
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=''): return 'Hello, ' + (name.capitalize() or 'World') + '!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=""): return "Hello, " + name.title()+"!" if len(name)>1 else "Hello, World!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name: str = "") -> str: """ Get "Hello, ${name}!" to a given name, or says "Hello, World!" if name is not given. """ return f"Hello, {name.title() or 'World'}!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=''): return f'Hello, {(name or "world").capitalize()}!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
hello = lambda n='': f"Hello, {n.title() or 'World'}!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(*name): if name: if name[0]: return ('Hello, ' + name[0].title() + '!') else: return 'Hello, World!' else: return 'Hello, World!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = ''): if name: return f"Hello, {name[0].capitalize() + name[1:].lower()}!" else: return "Hello, World!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=None): name = name.capitalize() if name else "World" return "Hello, %s!"%(name)
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name='World'): if not name: name = 'World' return f'Hello, {name.title()}!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
from typing import Optional def hello(*args) -> str: """ Get "Hello, ${name}!" to a given name, or says "Hello, World!" if name is not given. """ if args and len(args[0]): name = args[0] else: name = "world" return "Hello, {}!".format(name.title())
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(*name): if len(name)>0: return "Hello, "+name[0].lower().capitalize()+"!" if len(name[0])>0 else "Hello, World!" return "Hello, World!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=''): if name != "": return 'Hello, ' + name.capitalize() + '!' return 'Hello, World!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
import string def hello(name = "World"): if name == "": return "Hello, World!" else: return "Hello, " + name.capitalize() + "!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=None): try: test = name + str(name) print('No Error') except: name ='' print('Error Handled!!!') if name =='' or name == None: new_name = 'World' else: new_name = '' letter = 0 for i in name: if letter == 0 and i.islower: new_name += i.upper() elif letter ==0: new_name += i elif letter > 0 and i.isupper: new_name += i.lower() else: new_name += i letter += 1 return 'Hello, ' + new_name + '!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
hello = lambda n='', d='World': "Hello, %s!" % (n or d).title()
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = None): ans = "" if name is "" or name is None: return "Hello, World!" nm = list(name) for i in range(0, len(nm)): if i == 0: ans += nm[i].upper() else: ans += nm[i].lower() return "Hello, "+ans+"!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = 'World'): return 'Hello, %s!' %(name + int(not bool(name))* 'World').capitalize()
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=''): name = str(name) if name == 'None' or len(name) == 0 or name == ' '*len(name): return 'Hello, World!' else: return f'Hello, {name.title()}!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name='World'): if len(name) == 0: return 'Hello, World!' else: return 'Hello, ' + name.title() + '!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = ''): if not name: return 'Hello, World!' return f'Hello, {name[0].upper()}{name[1:].lower()}!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=None): return "Hello, World!" if name in ["",None] else "Hello, {}!".format(name.capitalize())
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name="World"): if name == "": name = "World" toLower = lambda x : x.lower() if len(x) > 0 else "" return "Hello, " + name[0].upper() + toLower(name[1:]) + "!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=''): if name != '' or len(name) != 0: name = name.lower() + "!" name = "Hello, " + name.capitalize() print(name) return name else: return 'Hello, World!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(*args): try: name = str(args[0]) return "Hello, " + name[0].upper() + name[1:].lower() + "!" except: return "Hello, World!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=''): return 'Hello, World!' if name is None or name == '' else f'Hello, {name.capitalize()}!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=""): return "Hello, World!" if len(name) <= 0 else "Hello, "+ name.lower().title() + "!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = 'World'): if not name: return 'Hello, World!' else: return f'Hello, {name.capitalize()}!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=None): return "Hello, World!" if name is None or name is '' else (f"Hello, {name.title()}!")
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
import string; def hello(name = ''): if name != '': return ('Hello, ' + (name.lower().capitalize()) + '!'); else: return ('Hello, World!');
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name='World'): if name == '': return 'Hello, World!' return 'Hello, {}!'.format(name[:1].upper() + name[1:].lower())
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = None): if name: capName = name.capitalize() if capName: return "Hello, {}!" .format(capName) else: return "Hello, World!" else: return "Hello, World!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name="world"): if name == '': name = 'world' return 'Hello, {}!'.format(name.title())
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=''): if not name or name == '': return 'Hello, World!' elif name: name = name.lower() return f'Hello, {name.title()}!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=""): if len(name) == 0: name = "World" return "Hello, " + str(name.lower()).capitalize() + "!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=False): return "Hello, {}!".format(name.capitalize()) if name else "Hello, World!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=""): if name: name = name.lower().capitalize() return "Hello, {}!".format(name) else: return "Hello, World!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = '') -> str: """ take (str: name) and return 'Hello, {name}!' if no name, return 'Hello, World!' """ return f"Hello, {name.title()}!" if name else "Hello, World!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=""): name = name.lower() name = name.title() if name != "": return f"Hello, {name}!" else: return f"Hello, World!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = 0): if not name: return "Hello, World!" else: return "Hello, " + name.capitalize() + "!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name="World"): if not name: return("Hello, World!") else: return("Hello, " + name.capitalize() + "!") hello() hello("John") hello("aLIce") hello("") hello('')
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=0): if name: name = name.title() return f'Hello, {name}!' else: return f'Hello, World!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name='World'): if(name == '' or name == 'World'): return 'Hello, World!' output = name.lower() output = output.split() output2 = output[(len(output)-1)] return 'Hello, ' + output2.capitalize() + '!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = None): if name == "" or name == None: return f'Hello, World!' else: return f'Hello, {name.capitalize()}!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=None): if name: a = name.lower() b = a.capitalize() return f"Hello, {b}!" elif not name: return "Hello, World!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=''): if len(name) == 0: return 'Hello, World!' ls = list(name) word = True for i in range(len(ls)): word = word and ls[i].isalpha() if word == True: return 'Hello, ' + name[0].upper() + name[1:].lower() + '!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name='World'): if name: return f'Hello, {name.lower().capitalize()}!' return 'Hello, World!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=""): if len(name.strip())==0: return "Hello, World!" else: a=name.title() return ("Hello, "+a+"!")
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = None): """ This function returns 'Hello, {Name}!' to a given name or says 'Hello, World!' if name is not given. """ if name is None or len(name) == 0: return 'Hello, World!' name = name.capitalize() return f'Hello, {name}!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name="World"): return "Hello, %s!" % (name.lower().capitalize() if name != "" else "World")
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = False): if name : return "Hello, " +name.capitalize() + "!" else : return "Hello, World!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = None): if name == '' or name == None: return "Hello, World!" else: name = name.lower() name = name.capitalize() return "Hello, " + name + "!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(*name): if(name == ()): return "Hello, World!" elif(name[0] == ""): return "Hello, World!" else: return 'Hello, '+name[0].lower().capitalize()+'!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name= "World"): if name =='': return 'Hello, World!' else: name = name.capitalize() return 'Hello, %s!' %(name) print((hello('John'))) print((hello('aLIce'))) print((hello())) print((hello("")))
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = "World"): if not name: name = "World" return "Hello, " + name.lower().capitalize() + "!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = "World"): if name == "": name = "World" name = list(name.lower()) name[0] = name[0].upper() return "Hello, {}!".format("".join(name))
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = ''): if name == "" or name == None : return "Hello, World!" else: name1 = name.lower() name2 = name1.capitalize() return f"Hello, {name2}!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=0): return "Hello, World!" if not name else "Hello, {}!".format(name.capitalize())
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=0): if name == "" or name == 0: return "Hello, World!" else: name = name.lower() name = name.capitalize() return "Hello, " + name + "!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name='World'): if name == None or name == '': return 'Hello, World!' else: return 'Hello, ' + str(name.lower().capitalize()) + '!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=""): if name != "": return f"Hello, { name.capitalize() }!" else: return "Hello, World!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name="World"): if name == "": return "Hello, World!" else: return f"Hello, " + name.title() + "!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=None): if name == None: return 'Hello, World!' elif name == '': return 'Hello, World!' else: name = name.capitalize() return 'Hello, ' + name + '!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = None): if name == None or len(name) < 1: return "Hello, World!" return f"Hello, {name.capitalize()}!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
import unittest def hello(name=None): return 'Hello, {}!'.format(name.capitalize() if name else 'World') class TestHello(unittest.TestCase): def test_hello_should_return_default_string_with_not_given_name(self): self.assertEqual(hello(None), 'Hello, World!') def test_hello_should_return_default_string_with_given_name_is_empty_string(self): self.assertEqual(hello(''), 'Hello, World!') def test_hello_with_only_lower_case(self): self.assertEqual(hello('abcde'), 'Hello, Abcde!') def test_hello_with_mixed(self): self.assertEqual(hello('aBcDe'), 'Hello, Abcde!')
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
import unittest HELLO = 'Hello' WORLD = 'World' EXCLAMATION_MARK = '!' DEFAULT_TEMPLATE = '{}, {}{}' def hello(name=None): def get_hello(word, hello_string=HELLO, exclamation_mark=EXCLAMATION_MARK): return DEFAULT_TEMPLATE.format(hello_string, word, exclamation_mark) return get_hello(word=name.title()) if name else get_hello(word=WORLD) class TestHello(unittest.TestCase): def test_hello_should_return_default_string_with_not_given_name(self): self.assertEqual(hello(None), 'Hello, World!') def test_hello_should_return_default_string_with_given_name_is_empty_string(self): self.assertEqual(hello(''), 'Hello, World!') def test_hello_with_only_lower_case(self): self.assertEqual(hello('abcde'), 'Hello, Abcde!') def test_hello_with_mixed(self): self.assertEqual(hello('aBcDe'), 'Hello, Abcde!')
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name = ''): if name == '' or type(name) != str: return 'Hello, World!' else: final_name = name[0].upper() + name[1:].lower() return 'Hello, ' + final_name + '!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=None): return f"hello, {name or 'world'}!".title()
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=""): if name == "": name="World" name = name[0].upper() + name[1:].lower() return f"Hello, {name}!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=None): if name is None: return 'Hello, World!' elif name == '': return 'Hello, World!' else: lower_name = name.lower() cap_name = lower_name.capitalize() return 'Hello, '+ cap_name + '!'
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name='World'): if len(name) < 1: name = 'World' return f"Hello, {name.title()}!"
Define a method ```hello``` that ```returns``` "Hello, Name!" to a given ```name```, or says Hello, World! if name is not given (or passed as an empty String). Assuming that ```name``` is a ```String``` and it checks for user typos to return a name with a first capital letter (Xxxx). Examples:
def hello(name=''): if name == '': return 'Hello, World!' else: name = name = ''.join(w[0].upper() + w[1:].lower() for w in name.split()) return f'Hello, {name}!'