Skip to content

Commit 939c058

Browse files
authored
Add files via upload
0 parents  commit 939c058

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+23164
-0
lines changed

Free Prac/Class3.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Sat Sep 15 09:19:13 2018
5+
6+
@author: student
7+
"""
8+
class Student:
9+
start_stud_id = 100 #class atrribute
10+
def get_fullname(self):
11+
return self.firstname + " " + self.lastname
12+
def __init__(self, name='NA', last='NA', phone='0'):
13+
self.firstname = name
14+
self.lastname = last
15+
self.email = name + '.' + last + '@cdac.com'
16+
self.phone = phone
17+
self.stud_id = Student.start_stud_id + 1
18+
Student.start_stud_id += 1
19+
20+
def stud_details(self):
21+
print(self.stud_id, ":", self.get_fullname())
22+
23+
print(Student.start_stud_id)
24+
s1 = Student('Aakash', 'Sharma', '+91 9836467')
25+
26+
print(Student.start_stud_id)
27+
s1.stud_details()
28+
29+
s2 = Student('Mohan', 'Pandit', '+91 937356')
30+
print(Student.start_stud_id)
31+
s2.stud_details()
32+
s3 = Student()
33+
print(Student.start_stud_id)
34+
s4 = Student()
35+
print(Student.start_stud_id)

Free Prac/Class4.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Sat Sep 15 09:33:23 2018
5+
6+
@author: student
7+
"""
8+
class Student:
9+
start_stud_id = 100 #class atrribute
10+
def get_fullname(self):
11+
return self.firstname + " " + self.lastname
12+
def __init__(self, name='NA', last='NA', phone='0'):
13+
self.firstname = name
14+
self.lastname = last
15+
self.email = name + '.' + last + '@cdac.com'
16+
self.phone = phone
17+
self.stud_id = Student.start_stud_id + 1
18+
Student.start_stud_id += 1
19+
def stud_details(self):
20+
print(self.stud_id, ":", self.get_fullname())
21+
def print_start_stud_id(self):
22+
print(Student.start_stud_id)
23+
24+
print(Student.start_stud_id)
25+
s1 = Student('Aakash', 'Sharma', '+91 9836467')
26+
s1.stud_details()
27+
s = [Student(), Student()]
28+
s1.print_start_stud_id()

Free Prac/Class5.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Sat Sep 15 09:47:15 2018
5+
6+
@author: student
7+
"""
8+
class Container():
9+
start_serial_code = 'ZRMUM01'
10+
container_size = '220 x 140'
11+
capacity_in_tons = 1030
12+
def __init__(self, serial_code):
13+
self.serial_code = Container.start_serial_code + str(serial_code)
14+
15+
def
16+
17+
c1 = Container(720)
18+
c1.contents = 'Books'
19+
20+
c2 = Container(721)
21+
c2.contents = 'Fish'
22+
23+
c3 = Container(722)
24+
print(c1.serial_code, c2.serial_code, c3.serial_code)
25+
print(c1.contents, c2.contents)

Free Prac/args.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Tue Sep 11 12:38:28 2018
5+
6+
@author: student
7+
"""
8+
9+
def employee(city, name='Aakash', age=18):
10+
print(city, '-> name =', name, 'and age =', age)
11+
12+
employee('Pune')
13+
employee('Pune', age=27)
14+
employee('Pune', 'Ajay')
15+
employee('Pune', 'Jatin', 25)
16+
17+
18+
19+
def employee2(*args, **kwargs):
20+
print(args)
21+
print(kwargs['age'])
22+
23+
employee2('Pune', 'Ajit', '+91 926346', age=26, profession='IT professional')
24+
#employee2('Pune', 27)
25+
#employee2('Pune')
26+
#employee2('Pune', 'Jatin', 25)

Free Prac/avg_sal.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Thu Sep 13 16:40:19 2018
5+
6+
@author: student
7+
"""
8+
try:
9+
with open('stud_info.csv', 'r') as stud_info:
10+
salaries = []
11+
for rec in stud_info:
12+
salaries.append(int(rec.split(',')[3]))
13+
print(sum(salaries)/len(salaries))
14+
except Exception as err:
15+
print(err)
16+
17+
18+
try:
19+
with open('stud_info.csv', 'r') as stud_info:
20+
salaries = []
21+
for rec in stud_info.readlines():
22+
salaries.append(int(rec.split(',')[3]))
23+
print(sum(salaries)/len(salaries))
24+
except Exception as err:
25+
print(err)
26+

Free Prac/banking.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import random
2+
3+
import sys
4+
5+
6+
class Banking():
7+
min_balance = 0
8+
9+
def __init__(self):
10+
self.balance = 0
11+
12+
def create_account(self, acc_type='Savings'):
13+
self.account_no = random.randint(100, 300)
14+
self.name = input("Enter name:")
15+
self.acc_type = acc_type
16+
17+
def getbalance(self):
18+
return self.balance
19+
20+
def withdraw(self, amount):
21+
if self.balance > amount:
22+
self.balance -= amount
23+
else:
24+
print("Insufficient Balance")
25+
26+
def deposit(self, amount):
27+
self.balance += amount
28+
29+
def display(self):
30+
print("Account no Name Account Type Balance")
31+
print(self.account_no, self.name, self.acc_type, self.balance)
32+
33+
34+
def Display(accounts):
35+
for i in accounts.values():
36+
i.display()
37+
38+
39+
def main():
40+
accounts = {}
41+
while True:
42+
43+
print("1.Create Account")
44+
print("2.Get Balance")
45+
print("3.Withdraw")
46+
print("4.Deposit")
47+
print("5.Display Info")
48+
ch = int(input("Enter Choice:"))
49+
if ch == 1:
50+
account = Banking()
51+
account.create_account()
52+
accounts[account.account_no] = account
53+
print("Account Created Successfully")
54+
elif ch == 2:
55+
print(account.getbalance())
56+
elif ch == 3:
57+
acc=int(input("Withdraw Account:"))
58+
amount = int(input("Enter Amount to be withdrawn"))
59+
accounts[acc].withdraw(amount)
60+
elif ch == 4:
61+
acc = int(input("Withdraw Account:"))
62+
amount = int(input("Enter Amount to be Added"))
63+
accounts[acc].deposit(amount)
64+
elif ch == 5:
65+
Display(accounts)
66+
67+
68+
main()

Free Prac/closure1.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Fri Sep 14 08:46:55 2018
5+
6+
@author: student
7+
"""
8+
''' closure is a function which remembers the values in
9+
enclosing scope even if they are not in memory'''
10+
def outer():
11+
x = 10
12+
a = 8
13+
b = 18
14+
print(hex(id(x)), hex(id(a)))
15+
def inner(y):
16+
return x+y+a
17+
return inner
18+
19+
local_fun = outer()
20+
print(type(local_fun))
21+
print(local_fun(50))
22+
print(local_fun.__closure__)
23+
24+
''' Closures are used as function factories.. which returns
25+
new and specialised functions '''
26+
27+
def raise_to(exp):
28+
def raise_to_exp(x):
29+
return pow(x,exp)
30+
#Python creates a closure to refer to exp obj
31+
return raise_to_exp
32+
33+
square = raise_to(2)
34+
cube = raise_to(3)
35+
print(square(5), cube(5))

Free Prac/closure2.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Fri Sep 14 09:15:38 2018
5+
6+
@author: student
7+
"""
8+
def conversion_price(currency):
9+
def price(qty):
10+
return qty * currency
11+
return price
12+
13+
dollar_to_rupees = conversion_price(69)
14+
pound_to_rupees = conversion_price(90)
15+
16+
print(dollar_to_rupees(30))
17+
print(pound_to_rupees(30))
18+
19+
''' Another example of closure '''
20+
def make_multiplier_of(n):
21+
def multiplier(x):
22+
return x * n
23+
return multiplier
24+
25+
times3 = make_multiplier_of(3)
26+
times5 = make_multiplier_of(5)
27+
times6 = make_multiplier_of(6)
28+
29+
print(times3(7))
30+
print(times5(7))

Free Prac/convert_int.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Thu Sep 13 14:38:23 2018
5+
6+
@author: student
7+
"""
8+
def convert_to_int(n):
9+
x = int(n)
10+
return x
11+
12+
def convert_to_float(n):
13+
y = float(n)
14+
return y

Free Prac/correct.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Wed Sep 12 15:50:43 2018
5+
6+
@author: student
7+
"""
8+
9+
def correct(s):
10+
print(s.split())
11+
return ' '.join(s.split()).replace('.', '. ')
12+
13+
s = 'python is fun.and it is actually a fun.End'
14+
print(correct(s))

0 commit comments

Comments
 (0)