-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintroduction.py
More file actions
521 lines (452 loc) · 13.4 KB
/
introduction.py
File metadata and controls
521 lines (452 loc) · 13.4 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
# print("Hello!!^_^")
# print("multiline comments by ctrl+/ same to undo")
# var=20
# print(var)
# print('var') #single quotes doesn't make it a character
# print(var,'var') #to print in the same line
# print(var,end='%')
# print('var') #when we want to use two print statements but output in one line, we use end kw.
# var=input()
# print(var)
# var=int(var)
# var=var+1
# print(var)
# name=input("Enter name")
# city=input("Enter city")
# phn=int(input("Enter phone number"))
# married=bool(input("Enter marital status")) # this prints true or false according to the input provided
# #if any input is provided then true else false in case if no input
# print('Name:' , name)
# print("City", city)
# print('phone', phn)
# print('married', married)
# a=4
# b=7
# a,b=b,a
# print(a,b)
####Reverse of a list
##list1[::-1]
# for i in range(0,10):
# print('Hello World ',i)
# for i in range(10,0,-1):
# print('Hello World ',i)
# for i in range(0,10,3):
# print(i)
# a=int(input('Enter starting range'))
# b=int(input('Enter stopping range'))
# if(a<b):
# for i in range(a,b+1):
# print(i,end=' ')
# elif(a>b):
# for i in range(b, a+1):
# print(i, end=' ')
# else:
# print("numbers are equal")
#
# for i in range(10): #start = 0 by default; step=+1, stop should be defined
# if(i==5):
# continue #continue continues the loop so 5 ko chdkr sb print hoga break b use krke dekho
# print(i)
# def fname():
# for i in range(4):
# print('Hello World')
# fname()
# print('how are u ??')
# a=int(input("Enter number 1"))
# b=int(input("Enter number 2"))
#
# def sum(a,b):
# return a+b
# var=sum(a,b)
# if(var%2==0):
# print("even sum")
# else:
# print("odd sum")
# for i in range(0,3):
# for j in range(0,i+1):
# print('*', end=' ')
# print() #for next line
# for i in range(3,0,-1):
# for j in range(0,i):
# print(j+1,end=' ')
# print()
# for i in range(0,3):
# for j in range(0,i+1):
# print(j+1, end=' ')
# print()
# def multiplevaluedfunc(first, second, *third): #here, *third variable is acting as a list it'll tk all values
# result=first+second
# for i in range(0,len(third)):
# result=result+third[i]
# print(result)
# multiplevaluedfunc(10,20,50,10,80,20)
# first=int(input('Enter first value'))
# second=int(input('Enter second value'))
# def division(first,second=1): #setting defalut value
# result=first/second
# print('Division result is : ',result)
#
# if(second==0):
# print('You have entered sec num as 0, that is invalid')
# division(first)
# else:
# division(first,second)
# def division(first,second):
# res=first/second
# print(res)
# division(second=10,first=20) #values can be sent accrdng to our order of argmnts
# str=input("Enter any string")
# for i in str:
# print(i)
# import calendar
# print(calendar.calendar(2019 ))
#Day3
# var="python"
# print(var[::-1])
# var="python"
# for i in range(len(var)-1, -1, -1):
# print(var[i], end=' ')
#list=[1,2,3,34,'abc','xyz',33.214, 67.5,True]
#print(list1)
# list1.append('append')
# print(list1)
# list1.insert(3,'inserted')
# print(list1)
# print(list1[3])
# print(list1[-3])
# print(len(list1))
# print(list1)
# print(list1[3:])
# print(list1[:3])
# print(list1[2:8:2])
#print(list1[20])
# newlist=list[:20]
# print(newlist)
####tuple####
# tup=(1,4,5,8,'ggj','ufhvjh', 37.7, 320.1, True)
# print(tup)
# print(len(tup)) #same as tuple, the only diff is () and can't b chnged
# dict1={
# "Name":'Berry',
# "Phone": 7060030972,
# 'Height': 5.8,
# 'Married':False
# }
# print(dict1)
# print(dict1['Name'])
# dict1['Name']='Jerry'
# dict1['City']='Kangra'
#
# print(dict1)
#
# compressedlist=[i for i in range(0,101) if(i%2==0)]
# print(compressedlist)
#
# list1=[int(input("Enter any value")) for i in range(0,10)]
# print(list1) #input in one line
# str=input("Enter a string seperated by 3 dots").split('.')
# print(str)
#Day4
# girls=['a','b','c']
# boys=['d','a','f']
# for i in girls:
# for j in boys:
# if(i==j):
# print("Same value",i)
# list_var=[2,34,12,23,67,89,13]
# new=list(filter(lambda x: x>30, list_var)) #list is a func
# print(new)
# dictionary={
# 0: 'Sunday',
# 1: 'Monday',
# 2: 'Tuesday',
# 3: 'Wednesday',
# 4: 'Thursday',
# 5: 'Friday',
# 6: 'Saturday'
# }
# list_week=[7,2,5,4,9,1,4,6]
# list_weekdays=list(map(lambda x: dictionary.get(x,"Not found"),list_week))
# print(list_weekdays)
#
# from functools import reduce
# list_var=[9,3,2,43,5,6,7]
# mult=reduce(lambda x,y : x*y, list_var) #reduce reduces the dataset
# print('Multiplication', mult)
# from functools import reduce
# listinp=[input("Enter values") for i in range(10)]
# convint=list(map(lambda x: int(x), listinp))
# listsum=reduce(lambda x,y: x+y, convint)
# print(listsum)
# import statistics
# list1=[20,30,40,10,9,35,24,12]
# a=statistics.median(list1)
# print("Median is :",a)
# l=list(filter(lambda x: x>a,list1))
# print(l)
# class Student:
# def __init__(self,name='Python'):
# self.name=name #here name is local variable and self.name is class variable
# print("Hello World")
# def welcome(self): #self is always the first parameter of any function
# print(self.name)
# print("welcome to Python Programming")
# obj=Student('Ishita')
# obj.welcome()
# obj1=Student()
# obj1.welcome()
# class Student:
# def __init__(self,name, address="Dehradun", phone=0):
# self.name=name #here name is local variable and self.name is class variable
# self.address=address
# self.phone=phone
# print("Welcome to the python world")
#
# def display(self): #self is always the first parameter of any function
# print("Printing student details")
# print(self.name)
# print(self.address)
# print(self.phone)
#
# name = input("Enter name")
# address= input("Enter address")
# phone = input("Enter phone number")
#
# if((len(address)>1) & (len(phone)>1)):
# phone = int(phone)
# obj=Student(name=name, address=address, phone=phone)
# obj.display()
# elif (len(address)>1 & (len(phone)==0)):
# obj=Student(name, address)
# obj.display()
# elif (len(phone)>1 & (len(address)==0)):
# phone=int(phone)
# obj=Student(name=name, phone=phone)
# obj.display()
# else:
# obj=Student(name)
# obj.display()
#
# class Student:
# def __init__(self,name,address='Dehradun',phone=0):
# self.name=name
# self.address=address
# self.phone=phone
#
# def display(self):
# print("Printing student details")
# print(self.name)
# print(self.address)
# print(self.phone)
#
# num=int(input("For how many students you want to store data?"))
# listobj=[]
# for i in range(0,num):
# name = input("Enter name")
# address= input("Enter address")
# phone = input("Enter phone number")
# if((len(address)>1) & (len(phone)>1)):
# phone = int(phone)
# i=Student(name=name, address=address, phone=phone)
# #obj.display()
# elif (len(address)>1 & (len(phone)==0)):
# i=Student(name, address)
# #obj.display()
# elif (len(phone)>1 & (len(address)==0)):
# phone=int(phone)
# i=Student(name=name, phone=phone)
# #obj.display()
# else:
# i=Student(name)
# #obj.display()
#
# listobj.append(i)
# dis=input("Do you want to print the details?: Press Y for yes ")
# if ( dis=='Y' or dis=='y'):
# for j in listobj:
# j.display()
##if we want to define a datatype, we use
## obj: Student
##similar to var=10, here datatype of var is int
##which we can also write as var : int
#EXCEPTIONAL HANDLING
# var_1 = input('Enter the value of first number: ')
# var_2 = input('Enter the value of second number: ')
#
# try:
# var_1 = int(var_1)
# var_2 = int(var_2)
#
# if (var_2 != 0):
# result = var_1 / var_2
# print('Division Result is: ', result)
# else:
# print('Value of second variable cannot be zero.')
# except ValueError:
# print("Can only enter integers")
# try:
# var_1 = int(var_1)
# var_2 = int(var_2)
#
# if (var_2 != 0):
# result = var_1 / var_2
# print('Division Result is: ', result)
# else:
# print('Value of second variable cannot be zero.')
# except ValueError:
# print("You can only enter integer numbers.")
# var_1 = input('Enter the value of first number: ')
# var_2 = input('Enter the value of second number: ')
#
# try:
# var_1 = int(var_1)
# var_2 = int(var_2)
#
# if (var_2 != 0):
# result = var_1 / var_2
# print('Division Result is: ', result)
# else:
# print('Value of second variable cannot be zero.')
# except ValueError:
# print("Enter integer values only.")
# # take input from the user till the time the values are not integer.
# while True:
# var1 = input('Enter the first number: ')
# var2 = input('Enter the second number: ')
#
# try:
# int_var1 = int(var1)
# int_var2 = int(var2)
# break
# except ValueError:
# print('Enter only integer values.')
#
#
# # take value from variable 1, 2 and 3. Compute the difference of variable 1, 2 and then
# # divide it's result from variable 3
# var1 = int(input('Enter the value of first number: '))
# var2 = int(input('Enter the value of second number: '))
# var3 = int(input('Enter the value of third number: '))
#
# result = var1 - var2
#
# division_result = var3/result
#
# print(division_result)
#INhertiance
# introduction to Classes -
# class Student: ## user defined datatype
# def __init__(self, name='Python'): # constructor
# self.name = name
# print("Hello World")
#
# def welcome(self):
# print(self.name)
# print('Welcome to python programming')
#
# obj = Student('Gurjas')
# obj.welcome()
# obj1 = Student()
# obj1.welcome()
#
#
# # Introduction to Inheritance
# class BaseClass:
#
# def __init__(self):
# self.var_1 = 2
# print("Base Class")
#
# def helloFxn(self, a=10):
# print("Hello Inside base class")
#
#
# class DerivedClass(BaseClass):
#
# def __init__(self):
# super().__init__()
# print("Derived Class")
# super().helloFxn(a=20)
# self.helloFxn()
#
# def helloFxn(self):
# print("Hello inside derived class")
#
# obj = DerivedClass()
#
#
# ## Static -- Students Class
#
# class Student:
# def __init__(self, name, address="Dehradun", phone=0):
# self.name = name
# self.address = address
# self.phone = phone
# print("Welcome to Brillica Services")
#
# def display_data(self):
# print("Printing students details")
# print(self.name)
# print(self.address)
# print(self.phone)
#
#
# name = input('Enter your name')
# address = input('Enter your address')
# phone = input('Enter your phone number')
#
# if ((len(address) > 1) & (len(phone) > 1)):
# phone = int(phone)
# obj = Student(name=name, address=address, phone=phone)
# obj.display_data()
# elif (len(address) > 1 & (len(phone) == 0)):
# obj = Student(name, address)
# obj.display_data()
# elif (len(phone) > 1 & (len(address) == 0)):
# phone = int(phone)
# obj = Student(name=name, phone=phone)
# obj.display_data()
# else:
# obj = Student(name)
# obj.display_data()
## Dynamic -- Students Class
# class Student:
# def __init__(self, name, address="Dehradun", phone=0):
# self.name = name
# self.address = address
# self.phone = phone
# print("Welcome to Brillica Services")
#
# def display_data(self):
# print("Printing students details")
# print(self.name)
# print(self.address)
# print(self.phone)
#
#
# students_count = input('Enter the number of records you want')
# students_count = int(students_count)
# students_records = []
# for i in range(students_count):
# print('Enter the details of student:')
# name = input('Enter the name of the student')
# address = input('Enter the address of the student')
# phone = input('Enter the phone number of the student')
#
# obj: Student
# if ((len(address) > 1) & (len(phone) > 1)):
# phone = int(phone)
# obj = Student(name=name, address=address, phone=phone)
# elif (len(address) > 1 & (len(phone) == 0)):
# obj = Student(name, address)
# elif (len(phone) > 1 & (len(address) == 0)):
# phone = int(phone)
# obj = Student(name=name, phone=phone)
# else:
# obj = Student(name)
#
# students_records.append(obj)
#
# for i in students_records:
# i.display_data()
#ato add new cell above, b to add cell down dd to delete in selection mode, press escape