-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.py
More file actions
251 lines (172 loc) · 4.09 KB
/
Copy pathpython.py
File metadata and controls
251 lines (172 loc) · 4.09 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
##---------Types of vlaue-----------------
int(21)
str("Arman")
float(3.1416)
bool()
##----------------------------------------
##---------sum of int---------------------
a=int(input("Enter the first number :"))
b=int(input("Enter the second number :"))
sum = a + b
print("The sum is :" , sum)
##----------------------------------------
##----------------------------------------
name = "Arman"
print(name)
print(name.upper())
print(name.lower())
print(name.find('n'))
print(name.replace("Arman","Avengers"))
print(name.replace("n","s"))
##---------------------------------------
##----------------Short cuts-----------------------
i =5
i = i+2 # =7
i += 2 # =7
i -= 2
i *= 2 # =14 # i = i*2
##--------operators precedence---------
result = 2 + 3 * 5 ## 3*5={}+2
print(result)
##----------Comparison Operators--------
print(3>2) # true
print(3<2) # false
print(3>=2)
print(3<=2) #(< + =)
print(3==2)
print(3!=2) # (! + =)
##-------Logical Opertors--------------
print(2 > 3 or 2 > 1) # true
print(2 > 3 and 2 > 1) # f
print(2 < 3 and 2 > 1) # t
print(not 2 < 3) #f
print(not 2 > 3) #t
##-------If - Else-----------------------
age = 19
if age >= 18:
print("You are an adult.")
print("You can vote.")
print("Thank You")
#-------
#You are an adult.
#You can vote.
#Thank You
#-------
age = 16
if age >= 18:
print("You are an adult.")
print("You can vote.")
elif age < 18 and age > 3:
print("You are in school.")
else:
print("You are a Child.")
print("Thank You")
#----
You are in school.
Thank You
#----
#--------Mini Project Calculator--------------
first = int(input("Enter the first number :"))
operator = input("Enter operator(+,-,*,/,%) :")
second = int(input("Enter the second number :"))
if operator == "+":
print(first + second)
elif operator == "-":
print(first - second)
elif operator == "*":
print(first * second)
elif operator == "/":
print(first / second)
elif operator == "%":
print(first % second)
else:
print("Invalid Operation")
##---------Range-------------
numbers = range(5)
print(numbers)
##---------------Loops---------------------
#------While-------
i = 1
while i <=100:
print(i) # print(i * "*")
i = i+1
#------Reverse---------
i = 5
while i >= 0:
print(i) # print(i * "*")
i = i-1
#------for-------------
for i in range(5):
print(i + 1) # print(i) = 0 1 2 3 4
##------------------List---------------------------
marks = [93,87,77, "Arman"]
print(marks) # print(marks[0]) # print(marks[-1]) {Reverce count} # print(marks[0:2])
#--------For loop in list-----------
marks = [93,87,77, "Arman"]
for score in marks:
print(score)
# Append
marks.append(68)
print(marks)
# insert
marks.insert(0,97)
print(marks)
# check
marks.insert(0,97)
print(93 in marks)
# How much elements
print(len(marks))
#--------while in list --------
marks = [93,87,77, "Arman"]
i = 0
while i < len(marks):
print(marks[i])
i = i + 1
# clear list
marks.clear()
print(marks)
##--------------------Break & Continue------------------
# Break
students = ["Arman","Jubeyar","Istiak","Israt","Ikra","joly"]
for student in students:
if student == "Israt":
break;
print(student)
# Continue
students = ["Arman","Jubeyar","Istiak","Israt","Ikra","joly"]
for student in students:
if student == "Israt":
continue;
print(student)
## ------------------Tuple (Unchangable) ---------------------
# Error!
marks = (95,98,97)
marks[0]=99 # Error!
# Count same
print(marks.count(97)) # = 3
# Index
print(index.count(97)) # = 2
# set
marks = {95,98,97,97,97}
print(marks)
# Index doesn't works in set.
marks = {95,98,97,97,97}
for score in marks:
print(score)
#---------------Dictionary--------------------
marks = {"Chemistry" : 93,"Biology" : 87}
print(marks["Chemistry"])
# Add
marks["Physics"] = 77;
print(marks)
# Change value
marks["Physics"] = 78;
print(marks)
#-------------------FUNCTIONS--------------------------
1. In-Built Functions = int , str
2. Module Functions = math
3. User-Defined Functions
# 2
import math
a = math.sqrt(16)
print(a)