-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringsChallenges.py
More file actions
89 lines (58 loc) · 1.67 KB
/
stringsChallenges.py
File metadata and controls
89 lines (58 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Given an inRange(x, y) function,
# write a method that determines whether a given pair(x, y) falls in the range(x < 1/3 < y).
# Essentially, you’ll be implementing the body of a function that takes in two numbers x and y and returns True if x < 1/3 < y
# otherwise, it returns False.
# checking whether true or false
def inRange(x, y):
return (x < 1/3 < y)
print(inRange(3, 4))
# Given a getStr() function,
# write the necessary sequence of operations to transform the string(containing three literals)
# in such a way that every literal is tripled respectively.
# Input
# A string
# Output
# Triple of every string literal
# Sample Input
# abc
# Sample Output
# aaabbbccc
# s = s[:position_to_insert] + char_to_insert + s[position_to_insert:]
def getStr(s):
s = s[:1] + s[0] + s[1:]
s = s[:1] + s[0] + s[1:]
s = s[:3] + s[3] + s[3:]
s = s[:3] + s[3] + s[3:]
s = s[:6] + s[6] + s[6:]
s = s[:6] + s[6] + s[6:]
strlen = len(s)
return [s, strlen]
print(getStr('abc')) # output -> aaabbbccc
# Input
# A string
# Output
# The first occurrence of “b” and “ccc” in the string
# Sample Input
# aaabbbccc
# Sample Output
# [3, 6]
def findOccurence(s):
b = s.find('b')
c = s.find('c')
return [b, c]
print(findOccurence('Iam a boy not a cat'))
# Problem Statement
# Given a function changeCase(s), the task is to convert the strings from upper case to lower case.
# Input
# A string in upper case
# Output
# Change case of the string in lower case
# Sample Input
# “AAA BBB CCC”
# Sample Output
# “aaa bbb ccc”
def changeCases(s):
a = s.upper()
b = s.lower()
return[a, b]
print(changeCases("aaaaa, BBAMAJ"))