Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ArshiaRx authored Aug 24, 2021
1 parent eb195f7 commit 7a6c399
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
23 changes: 23 additions & 0 deletions String-2/count_hi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#CodingBat - Python

#count_hi

#Return the number of times that the string "hi" appears anywhere in the given
#string.

# count_hi('abc hi ho') → 1
# count_hi('ABChi hi') → 2
# count_hi('hihi') → 2

def count_hi(str):
count = 0
for e in range(len(str)-1):
next_two = str[e:e+2]
if next_two == "hi":
count += 1
return count


print(count_hi('abc hi ho'))
print(count_hi('ABChi hi'))
print(count_hi('hihi'))
37 changes: 37 additions & 0 deletions String-2/double_char.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#CodingBat - Python

#double_char

#Given a string, return a string where for every char in the original, there
#are two chars.

# double_char('The') → 'TThhee'
# double_char('AAbb') → 'AAAAbbbb'
# double_char('Hi-There') → 'HHii--TThheerree'

def double_char(str):

result = ""
for i in range(len(str)):
result += str[i] + str[i]

return result


print(double_char('The'))
print(double_char('AAbb'))
print(double_char('Hi-There'))
# =============================================================================

# def double_char(str):
# str2 = ""
# for i in str:
# str2 = str2 + i + i
# return str2


# def double_char(str):
# str2 = ""
# for e in str:
# str2 += (e * 2)
# return str2

0 comments on commit 7a6c399

Please sign in to comment.