-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpro_2.py
More file actions
155 lines (136 loc) · 3.22 KB
/
pro_2.py
File metadata and controls
155 lines (136 loc) · 3.22 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
a = 10-3
b = 56
b /= 3
print(a + b)
# comparision orparator
a = 5==5
print(a)
a = True or False
print(a)
print("this is :", True or False)
print("this is :", True or True)
print("this is :" , False or False)
#and
b = True and False
print(b)
print("ths is :", True and False)
print("THIS IS :", True and True)
print("this is :", False and False)
# NOT
print(not(False))
L = ["aa","bb","cc"]
# print(L.append("dd"))
# print(L.pop(0))
# print(L.sort())
print(L.reverse())
print(L)
m = ([1,2,3],
[4,5,6],
[7,8,9]
)
col2 = [row[1] for row in m]
print(col2)
row1 = [col2[2] for col2 in m]
print(row1)
col2 = [row[1] for row in m if row[1] % 2 == 0]
print(col2)
col2 = [row[2] for row in m if row[2] % 2 == 0]
print(col2)
col1 = [row[0] for row in m if row[0] % 2 == 0]
print(col1)
# string function
n = "adithyan"
name = n[0:8:2]
print(name)
print(name.endswith("ha"))
print(name.startswith("adi"))
name1 = "adithyan"
print(name1.endswith("yan"))
print(name1.startswith("yan"))
print(name1.capitalize())
c = " hello , world "
print("this is strip fu: "+c.strip())
print("this is split fu: "+str(c.split()))
print("this is upper fu: "+c.upper())
print("this is lower fu: "+c.lower())
print("this is join fu: "+" ".join(c))
print("this is replace fu: "+c.replace("hello","bye"))
print("this is find fu; "+str(c.find("l")))
s1 = "123"
s2 = "abc"
s3 = "abc123"
print("this is numeric: "+str(s1.isdigit()) )
print("this is alph: "+str(s2.isalpha()) )
print("this is alphnum : "+str(s3.isalnum()) )
age = 16
name = "adithyan"
print(f"hello!! ,i am {name} and i am {age} years old ")
print("hello!! ,i am {} and i am {} years old ".format(name,age))
# int functon
print("this is divmod: ",divmod(21,3) )
print("this is pow : ",pow(5,2))
print("this is abs : ",abs(-10))
print("this is in bin val: ", bin(150))
print("this is in hex val: ",hex(1400))
print("this is in oct val: ",oct(140))
# palandrome question
def is_palandrome(s):
cleaned_str = " ".join(char.lower() for char in s if char.isalnum())
return cleaned_str == cleaned_str[::-1]
print(is_palandrome("no lemon , melon on"))
print(is_palandrome("s8008s"))
print(is_palandrome("bool"))
# control statement
# if statement
x = 25
if x > 20:
print("x is greater than 20 ")
# elif statement
x1 = 15
if x1 < 5:
print("x is smaller than 5")
elif x1 <= 15:
print("x is greater then 15")
# else statement
x2 = 5
if x2 < 2:
print("x is smaller than 5")
elif x2 == 5:
print("x is equal to 5")
elif x2 != 5:
print("x is not equal to 5")
else:
print("x is grater than 5")
# if,elif and else combining
sales = 89
if sales > 95:
print("excelent: A+")
elif sales > 85:
print("good: A")
elif sales > 65:
print("hmm not bad: B+")
elif sales > 45:
print("need to improve man!!: B")
else:
print("very bad!!: C")
# nested if statement
y = 15
y1 = 20
if y > 10:
if y1 > 15:
print("it is greater than it was")
else:
print("it is not right answer")
else:
print("y is smallert than it was")
# logical operator
xa = 15
ya = 5
if xa > 4 and ya > 10:
print("this is correct way for operator")
if xa > 20 or ya < 3:
print("the OR statement is correct")
else:
print("this is not correct in AND")
if not xa < 10:
print("NOT operator is correct")