-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasics.py
More file actions
103 lines (89 loc) · 1.83 KB
/
Basics.py
File metadata and controls
103 lines (89 loc) · 1.83 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#First Script
print("Hello World")
#Variable declarations
num1 = 4
print(num1)
num2 = 4.5
print(num2)
str1 = "Movie Time"
print(str1)
#List of mixed datatypes
list1 = []
list1.append(num1)
list1.append(num2)
list1.append(str1)
print(list1)
#Input - Output
name = input()
num1 = int(input())
print(name)
print(num1)
#Conditions
if(num1>10):
print("Greater than 10")
elif(num1<5):
print("Less than 5")
else:
print("Else")
def mean(self, N, A):
sum = 0
for a in A:
sum += a
sum = sum/N
return int(sum)
def hello():
print("Stepping into first function")
for i in range(5):
print(i)
hello()
#String functions
S = "AbcdE"
#Converting String to lower case
print(S.lower())
#Print reversed String
print(S[::-1])
#Delete alternate characters from String
print(S[::2])
#Remove Space from String
def modify(self, s):
# code here
op = ""
for ch in s:
if(ch!=' '):
op += ch
return op
#Count camel case characters in String
def countCamelCase (self,s):
# your code here
count = 0
i = 0
for ch in s:
if(ch>='A' and ch<='Z'):
count+=1
i+=1
return count
#Substring
def javaSub (ob, S, L, R):
# code here
n = len(S)
if L<0:
L = 0
if R>(n-1):
R = n-2
return S[L:R+1]
#Absulute diiferece between diagonals
def diagonalSumDifference(self,N,Grid):
#code here
ldiag = 0
rdiag = 0
for i in range(N):
ldiag += Grid[i][i]
rdiag += Grid[N-1-i][i]
return abs(ldiag - rdiag)
#Regex: Remove all alphabets from String
def removeCharacters(self, S):
# code here
result = ""
pattern = r'[a-zA-Z+$]'
result = re.sub(pattern, '', S)
return result