Skip to content

Commit b9dc7df

Browse files
committed
added string-1 problems
1 parent 0191f7c commit b9dc7df

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

Solutions/string-1/extra_end.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Given a string, return a new string made of 3 copies of the last 2
2+
# chars of the original string. The string length will be at least 2.
3+
4+
# extra_end('Hello') → 'lololo'
5+
# extra_end('ab') → 'ababab'
6+
# extra_end('Hi') → 'HiHiHi'
7+
8+
9+
def extra_end(str):
10+
return str[-2:] * 3

Solutions/string-1/first_two.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Given a string, return the string made of its first two chars,
2+
# so the String "Hello" yields "He". If the string is shorter
3+
# than length 2, return whatever there is, so "X" yields "X",
4+
# and the empty string "" yields the empty string "".
5+
6+
# first_two('Hello') → 'He'
7+
# first_two('abcdefg') → 'ab'
8+
# first_two('ab') → 'ab'
9+
10+
11+
def first_two(str):
12+
if len(str) > 2:
13+
return str[0:2]
14+
return str

Solutions/string-1/make_out_word.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Given an "out" string length 4, such as "<<>>", and a word, return a new
2+
# string where the word is in the middle of the out string, e.g. "<<word>>".
3+
4+
# make_out_word('<<>>', 'Yay') → '<<Yay>>'
5+
# make_out_word('<<>>', 'WooHoo') → '<<WooHoo>>'
6+
# make_out_word('[[]]', 'word') → '[[word]]'
7+
8+
9+
def make_out_word(out, word):
10+
return out[:2] + word + out[-2:]

0 commit comments

Comments
 (0)