diff --git a/cse16218_ex2_10.py b/cse16218_ex2_10.py new file mode 100644 index 0000000000000000000000000000000000000000..7d45c9c85ec5c42abf6b5feb6f28ad71e777de09 --- /dev/null +++ b/cse16218_ex2_10.py @@ -0,0 +1,23 @@ +def depth(s, n): + current_max = 0 + final_max = 0 + + for i in range(n): + if s[i] == '(': + current_max += 1 + + if current_max > final_max: + final_max = current_max + elif s[i] == ')': + if current_max > 0: + current_max -= 1 + else: #unbalanced + return -1 + + if current_max != 0: #unbalanced + return -1 + + return final_max + +s = input() +print (depth(s, len(s))) diff --git a/cse16218_ex2_2.py b/cse16218_ex2_2.py new file mode 100644 index 0000000000000000000000000000000000000000..744a6ec12884087f72989583a5ce964a9d70118c --- /dev/null +++ b/cse16218_ex2_2.py @@ -0,0 +1,6 @@ +s = str(input()) + +for i in range(97, 123): + v = s.count(chr(i)) + if(v>0): + print(chr(i) + ": " + str(v)) diff --git a/cse16218_ex2_4.py b/cse16218_ex2_4.py new file mode 100644 index 0000000000000000000000000000000000000000..3215086fce39c90d53b2b9ae36752750892fdb21 --- /dev/null +++ b/cse16218_ex2_4.py @@ -0,0 +1,8 @@ +s = list(input()) + +for i in range(1, len(s)): + if(s[i] == s[0]): + s[i] = "$" + +s = "".join(s) +print(s) diff --git a/cse16218_ex2_5.py b/cse16218_ex2_5.py new file mode 100644 index 0000000000000000000000000000000000000000..d3f23fc35edf1044c48a86d4c886ae76acac544e --- /dev/null +++ b/cse16218_ex2_5.py @@ -0,0 +1,7 @@ +a = input("Enter the first string") +x = a[:2] +x1 = a[2:] +b = input("Enter the Second String") +y = b[:2] +y1 = b[2:] +print (y+x1+" "+x+y1) diff --git a/cse16218_ex2_6.py b/cse16218_ex2_6.py new file mode 100644 index 0000000000000000000000000000000000000000..ddd30b74a7f076e7121cf62c2120282445576375 --- /dev/null +++ b/cse16218_ex2_6.py @@ -0,0 +1,3 @@ +str=["PHP", "Exercises", "Backend"] +c=max(str,key=len) +print(c) diff --git a/cse16218_ex2_7.py b/cse16218_ex2_7.py new file mode 100644 index 0000000000000000000000000000000000000000..2deaa128f01a9abf34c88e19cd2cd656fb449454 --- /dev/null +++ b/cse16218_ex2_7.py @@ -0,0 +1,3 @@ +str = "Ganesh" +print(str.upper()) +print(str.lower()) diff --git a/cse16218_ex2_8.py b/cse16218_ex2_8.py new file mode 100644 index 0000000000000000000000000000000000000000..c14aadd75a3e8d00596932201bbfe225b93f678e --- /dev/null +++ b/cse16218_ex2_8.py @@ -0,0 +1,3 @@ +n=input("Enter the String :") +if len(n)%4 == 0: + print(n[::-1]) diff --git a/cse16218_ex2_9.py b/cse16218_ex2_9.py new file mode 100644 index 0000000000000000000000000000000000000000..4939509291309a00864e89137e9fabd3bcaf9fb5 --- /dev/null +++ b/cse16218_ex2_9.py @@ -0,0 +1,16 @@ +def encrypt(string, shift): + + cipher = '' + for char in string: + if char == ' ': + cipher = cipher + char + elif char.isupper(): + cipher = cipher + chr((ord(char) + shift - 65) % 26 + 65) + else: + cipher = cipher + chr((ord(char) + shift - 97) % 26 + 97) + + return cipher + +s= input("String: ") +shift = int(input("Shift: ")) +print("Encrypted String: ", encrypt(s, shift))