Coding Bat: Python. String-1

All solutions were successfully tested on 15 April 2013.

hello_name:

def hello_name(name):
  return "Hello " + name + "!"

make_abba:

def make_abba(a, b):
  return a + b + b + a

make_tags:

def make_tags(tag, word):
  return "<" + tag + ">" + word + "</" + tag + ">"

make_out_word:

def make_out_word(out, word):
  return out[:2] + word + out[2:]

extra_end:

def extra_end(str):
  return str[-2:] * 3

The asterisk is overloaded in Python, as you see in this example. An alternative solution would be to concatenate with “+”, as you’ve seen it before.

first_two:

def first_two(str):
  if len(str) <= 2:
    return str
  return str[:2]

first_half:

def first_half(str):
  return str[:len(str)/2]

without_end:

def without_end(str):
  return str[1:-1]

combo_string:

def combo_string(a, b):
  if len(a) > len(b):
    return b + a + b
  return a + b + a

non_start:

def non_start(a, b):
  return a[1:] + b[1:]

left2:

def left2(str):
  return str[2:] + str[:2]

Leave a Reply

Your email address will not be published. Required fields are marked *

Spammer prevention; the answer is an integer: * Time limit is exhausted. Please reload CAPTCHA.