-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmyParactice.py
More file actions
476 lines (347 loc) · 9.15 KB
/
myParactice.py
File metadata and controls
476 lines (347 loc) · 9.15 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
print("New file")
# print("Hellow how are \"hehha\"\ you")
# print("Hy",8,9,sep="~",end="--")
# print("yes")
# print(15/3)
# print(15//3)
# print(17%3)
# print(2**70)
#Calculator
# value_one=int(input("Enter First value : "))
# value_two=int(input("Enter Second value : "))
# print(f"Sum of {value_one} and {value_two} is = ",value_one+value_two)
# print(f"Multiplication of {value_one} and {value_two} is = ",value_one*value_two)
# print(f"Division of {value_one} and {value_two} is = ",value_one/value_two)
#Type Casting
# c=1.1
# d=9
# print(c+d)
# Exercise
# import time
# timestamp=time.strftime('%H:%M:%S')
# print('Current Time ::',timestamp)
# Hour=int(time.strftime('%H'))
# Minute=int(time.strftime('%M'))
# Second=int(time.strftime('%S'))
# if 5<=Hour<12:
# print('Good Morning')
# elif 12 <= Hour < 17:
# print('Good Afternoon')
# elif 17 <= Hour < 21:
# print('Good Evening')
# else:
# print('Good Night')
#Match Case in Python
# x=int(input('Enter any number between 1 to 5 :'))
# match x:
# case 0:
# print(x,' The number you enter is zero')
# case 1:
# print(x, 'The number you enter is one')
# case 2:
# print(x, 'The number you enter is two')
# case 3:
# print(x, 'The number you enter is three')
# case 4:
# print(x, 'The number you enter is four')
# case 5:
# print(x, 'The number you enter is five')
# case _:
# print(x,' The number does not lies between 1 to 5')
#For Loop in python
# colors=["Red","Blue","Green","Purple"]
# for color in colors:
# print(color)
# for i in color:
# print(i)
# for each in range(1,11):
# print(each)
#Range with difference
# for even in range(0,101,2):
# print(even)
# for odd in range(1,100,2):
# print(odd)
#While Loop
# i=0
# while i<5:
# print(i)
# i=i+1
#Break and Continue
# for x in range(1,21):
# print("5 x ",x ,"=",5*x)
# if (x==10):
# break
# for y in range(1,21):
# if (y==10):
# print("10 is here")
# continue
# print("4 x ",y ,"=",4*y)
#Function
#if you want to define function body latter then you write pass in function body
# def calculateGemMean(a,b):
# mean=(a*b)/(a+b)
# print(mean)
# calculateGemMean(50,10)
#Dictionary and tuple type in function argument
#Tuple
# def average(*number):
# print(type(number))
# sum=0
# for i in number:
# sum=sum+i
# print("Average is ",sum/len(number))
# average(5,4,3)
# def name(**name):
# print(type(name))
# print("Hello ",name["fname"],name['mname'],name["lname"])
# name(fname="Ali",mname="Ahmed",lname="Khan")
#List in Python
# list=[4,9,8,4,3,1,3,2,8]
# print(list)
# print(list[0])
# for i in list:
# print(i)
# print(len(list))
# #for negavtive index it would be len(list) minus negative index in our case length is 3 and -1 it gives 2 so on -1 we get 8
# print(list[-1])
# #in keyword with if condition , same thing apply for string also
# if 19 in list:
# print("Yes")
# else:
# print("No")
# print(list[1:9:2])
#list method
# myList=[1,23,1,2,3,2,14]
# print(myList)
# myList.append(7)
# myList.reverse()
# print(myList)
# secondlist=myList
# secondlist[0]=100
# print(myList)
# #the upper methods change the orignal list recommended to use .copy function
# thirdlist=myList.copy()
# thirdlist[0]=90
# thirdlist.insert(3,9000)
# thirdlist.extend(secondlist)
# merge=thirdlist+myList+secondlist
# print(merge)
# print(thirdlist)
#Tuple
#tuple are not editable or change able
# tup=(12,22,221)
# count=tup.count(12)
# print(count)
# print(tup)
#String formating in python
# name="Ali"
# country="Pakistan"
# price=2.2220303
# print(f"My name is {name} and i am form {country}")
# print(f"My name is {name} and i am form {country}, in my country the price of meet is {price:.2f}")
#doc string method
# def square(n):
# '''Take n and print squares of it'''
# print(n**2)
# square(5)
# print(square.__doc__)
#Factorial Recursion
# def factorial(n):
# if(n==0 or n==1):
# return 1
# else:
# return n * factorial(n-1)
# print(factorial(5))
#Fibbonacci sequence
# def fibonacci_recursive(n):
# if n <= 0:
# return 0
# elif n == 1:
# return 1
# else:
# return fibonacci_recursive(n-1) + fibonacci_recursive(n-2)
# n = 10
# for i in range(n):
# print(fibonacci_recursive(i), end=" ")
#set in python and its method
# s1={2,1,3,4,32,12,1,2,5}
# s2={12,11,32,14,1,12,51}
# print(s1)
# print(s1.union(s2))
# s1.update(s2)
# print(s1)
# s3=s1.symmetric_difference(s2)
# print(s3)
#Dictionary
# disc={
# "Ali":"is a good boy",
# "Jhelum":"Is my Home Town",
# }
# print(disc["Ali"])
# for key in disc.keys():
# print(f"The Value of key {key} is {disc[key]}")
#Set unordered disctionary ordered
#For lopp with else in python
# for i in range(5):
# print(i)
# if i==3:
# break
# else:
# print('Loop break')
#Error Handling in Python
# a=input("Enter number for table : ")
# print(f"Multiplication of table {a} is : ")
# try:
# for i in range(1,11):
# print(f"{int(a)} X {i} = {int(a)*i}")
# except Exception as e:
# print(e)
# print("Out of program")
#Finally Keyword
# try:
# l=[1,5,7,8]
# i=int(input("Enter index : "))
# print(l[i])
# except:
# print("Some Error Occur")
# finally:
# print("I am always executed")
#Custom Error
# num=int(input("Enter and number less than 3 or greater than 12 : "))
# if 3<= num <= 12:
# raise ValueError("Value Should be not in range")
#Encryption Exercise
# def encryDeycry():
# msg=input("Enter your message : ")
# def decryption(msg):
# msg_length=len(msg)
# if msg_length<=3:
# reverse_msg=msg[::-1]
# print(reverse_msg)
# encryDeycry()
# elif 3< msg_length <=7:
# format_msg=msg[1:-1]
# reverse_msg=format_msg[::-1]
# print(reverse_msg)
# encryDeycry()
# elif 8<= msg_length <=20:
# format_msg=msg[3:-3]
# reverse_msg=format_msg[::-1]
# print(reverse_msg)
# encryDeycry()
# decryption(msg)
# encryDeycry()
#Short Hand Expression
# a=200
# b=30
# c=9 if a>b else 2
# print(c)
#Enumerate Function in Python to get index also
# marks=[12,13,14,11,21,323,232,112,55,343]
# for index,mark in enumerate(marks):
# print(f"At index {index} is {mark}")
#Virtual Environment in Python
#python -m venv myenv
#How to Activate this virtual environment
#myenv/Scripts/activate
#.\Activate.ps1
#How to disclose or deactivate virtual environment
#exit
#How to get list of all packages in virtual environment
#pip freeze
#pip freeze > requirements.txt
#How to activate all virtual environment packages in our virtual environment
#pip freeze -r requirements.txt
#It activate all packagesin our virtual environment
# import math
# floatnum=math.floor(4.0909)
# squareroot=math.floor(math.sqrt(81))
# print(squareroot)
# print(floatnum)
# # print(dir(math))
# # from paractice import welcome, otherfile
# import paractice
# print(paractice.welcome())
# print(paractice.otherfile)
# import os
# if(not os.path.exists("PythonData")):
# os.mkdir("PythonData")
# for i in range (1,100):
# os.mkdir(f"PythonData/Day{i}")
#list
#folders=os.listdir("PythonData")
# for i in range (1,100):
# os.rename(f"PythonData/Day{i}",f"Tutorial {i}")
# file=open('myfile.txt','w')
# text=file.write("Yes yo do it")
# print(text)
# file.close()
#File Module With more functionality
# myfile = open('myfile.txt', 'r')
# content = myfile.read()
# print(content)
# myfile.close()
# with open('myfile.txt', 'r') as myfile:
# for line in myfile:
# print(line.strip())
# with open('myfile.txt','r') as f:
# print(type(f))
# f.seek(2) #Skip first 2
# data=f.read(5) #read net 5
# print(data)
# Lamda Function
# def double(x):
# return x*2
# double=lambda x:x*2
# print(double(50))
# def appl(fx,value):
# return 7+fx(value)
# print(appl(double,5))
# print(appl(lambda x:x*2,5))
#Map , List , Filter ,Reducer
# def cube(x):
# return x*x*x
# print(cube(2))
# l=[1,2,3,4,7,9]
# newl=list(map(cube,l))
# print(newl)
# def filter_function(a):
# return a>4
# newnew1=list(filter(filter_function,l))
# print(newnew1)
# # value = 1 # Start with 1
# # for day in range(1, 65): # 1 to 64 days
# # print(f"Day {day}: {value}")
# # value *= 2 # Double the value each day
# #Reduce function
# from functools import reduce
# numbers=[1,2,3,4,5]
# def mySum(x,y):
# return x+y
# sum=reduce(mySum,numbers)
# print(sum)
#Is Vs ==
# a=4
# b=4
# print(a is b) #compare location in memory
# print(a == b) #Compare value
#Classes and Object in Memory
# class Person:
# def __init__(self,name,occupation):
# self.name=name
# self.occupation=occupation
# def info(self):
# print(f"{self.name} is a {self.occupation}")
# a=Person("Ahmed","HR")
# a.info()
#Decorators
def greet(fx):
def mfx(*args,**kwargs):
print("Good Morning")
fx(*args,**kwargs)
print("Thanks for using this function")
return mfx
@greet
def hello():
print("Hellow World")
hello()