Skip to content

Commit 82ba0be

Browse files
authoredFeb 8, 2020
Add files via upload
0 parents  commit 82ba0be

31 files changed

+519
-0
lines changed
 

‎1.OOP_basics.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Student:
2+
Newname='Aayush'
3+
Newmarks=68
4+
def __init__(self,a):
5+
self.a=a
6+
7+
def add(self):
8+
n = int(input())
9+
for i in range (n):
10+
name=input()
11+
marks=int(input())
12+
self.a=a.append(name)
13+
self.a=a.append(marks)
14+
print(a)
15+
a=list()
16+
s=Student(a)
17+
s.add()
18+
print(getattr(s,'Newname',67))
19+
setattr(s,'Newname','Satyam')
20+
print(getattr(s,'Newname',56))
21+
print(hasattr(s,'Oldname'))
22+
delattr(Student,'Newmarks')
23+
print(hasattr(s,'Newmarks'))

‎10.facebook_socket.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import socket # for socket
2+
import sys
3+
4+
try:
5+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
6+
print("Socket successfully created")
7+
except socket.error as err:
8+
print("socket creation failed with error %s" % (err))
9+
10+
# default port for socket
11+
port = 80
12+
13+
try:
14+
host_ip = socket.gethostbyname('www.facebook.com')
15+
except socket.gaierror:
16+
17+
# this means could not resolve the host
18+
print("there was an error resolving the host")
19+
sys.exit()
20+
21+
# connecting to the server
22+
s.connect((host_ip, port))
23+
24+
print("the socket has successfully connected to facebook on port == %s" % (host_ip))

‎11threading.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from _thread import start_new_thread as tdd
2+
import time
3+
def func(i):
4+
fact = 1
5+
while(i>0):
6+
fact=fact*i
7+
i-=1
8+
print(fact)
9+
tdd(func,(1,))
10+
time.sleep(0.5)
11+
tdd(func,(2,))
12+
time.sleep(0.5)
13+
14+
tdd(func,(3,))
15+
time.sleep(0.5)
16+
17+
tdd(func,(4,))
18+
time.sleep(0.5)
19+
input()

‎12multithreading.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from threading import Thread
2+
import time
3+
class Hello(Thread):
4+
def run(self):
5+
for i in range(5):
6+
print("Hello")
7+
time.sleep(2)
8+
9+
class Hi(Thread):
10+
def run(self):
11+
for i in range(5):
12+
print("Hi")
13+
time.sleep(2)
14+
t1=Hello()
15+
t2=Hi()
16+
t1.start()
17+
time.sleep(0.5)
18+
t2.start()
19+
time.sleep(0.5)
20+
t1.join()
21+
t2.join()

‎13.multithreading advanced.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import threading
2+
import time
3+
4+
5+
class myThread (threading.Thread):
6+
def __init__(self, threadID, name, counter):
7+
threading.Thread.__init__(self)
8+
self.threadID = threadID
9+
self.name = name
10+
self.counter = counter
11+
def run(self):
12+
print("Starting " + self.name)
13+
threadLock.acquire()
14+
print_time(self.name, self.counter,1)
15+
threadLock.release()
16+
print("Exiting " + self.name)
17+
18+
def print_time(threadName, counter, delay):
19+
while counter:
20+
time.sleep(delay)
21+
print("%s: %s %s" % (threadName, time.ctime(time.time()),counter))
22+
counter -= 1
23+
24+
threadLock=threading.Lock()
25+
26+
# Create new threads
27+
thread1 = myThread(1, "Payment", 5)
28+
thread2 = myThread(2, "payment confirmation", 5)
29+
30+
# Start new Threads
31+
thread1.start()
32+
thread2.start()
33+
thread1.join()
34+
thread2.join()
35+
print("Exiting Main Thread")

‎13b.Multithreding.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import queue
2+
import threading
3+
import time
4+
5+
exitFlag = 0
6+
7+
class myThread (threading.Thread):
8+
def __init__(self, threadID, name, q):
9+
threading.Thread.__init__(self)
10+
self.threadID = threadID
11+
self.name = name
12+
self.q = q
13+
def run(self):
14+
print("Starting " + self.name)
15+
process_data(self.name, self.q)
16+
print("Exiting " + self.name)
17+
def process_data(threadName, q):
18+
while not exitFlag:
19+
queueLock.acquire()
20+
if not(workQueue.empty()):
21+
data = q.get()
22+
queueLock.release()
23+
print("%s processing %s" % (threadName, data))
24+
else:
25+
queueLock.release()
26+
time.sleep(1)
27+
28+
threadList = ["Thread-1", "Thread-2", "Thread-3"]
29+
nameList = ["One", "Two", "Three", "Four", "Five"]
30+
queueLock = threading.Lock()
31+
workQueue = queue.Queue(10)
32+
threads = []
33+
threadID = 1
34+
35+
# Create new threads
36+
for tName in threadList:
37+
thread = myThread(threadID, tName, workQueue)
38+
thread.start()
39+
threads.append(thread)
40+
threadID += 1
41+
42+
# Fill the queue
43+
queueLock.acquire()
44+
for word in nameList:
45+
workQueue.put(word)
46+
queueLock.release()
47+
48+
# Wait for queue to empty
49+
while not workQueue.empty():
50+
pass
51+
52+
# Notify threads it's time to exit
53+
exitFlag = 1
54+
55+
# Wait for all threads to complete
56+
for t in threads:
57+
t.join()
58+
print("Exiting Main Thread")
59+

‎14variable input.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def sum(x,*y):
2+
c=x
3+
for i in y:
4+
c=c+i
5+
print(c)
6+
sum(5,6,7,8,9)

‎2a.method_overloading.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#method overloading
2+
class Person:
3+
def area(self,l=None,b=None):
4+
self.l=l
5+
self.b = b
6+
if l!=None and b!=None:
7+
ar=l*b
8+
else:
9+
ar=l*l*3.14
10+
print(ar)
11+
s=Person()
12+
s.area(2)

‎2b.MethodOverriding.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#method overriding
2+
class Person:
3+
def __init__(self):
4+
self.value=5
5+
def display(self):
6+
return self.value
7+
class Student(Person):
8+
def display(self):
9+
return self.value+1
10+
s=Student()
11+
print(s.display())

‎2c.doc_dict.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#doc and dict in python
2+
class Student:
3+
"""I am awesome"""
4+
5+
s=Student()
6+
print(s.__doc__)
7+
def __init__(self):
8+
print("Hello from the other side")
9+
print(Student.__dict__)

‎3.constructor&dest.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Students:
2+
3+
def __init__(self,counter,name,age):
4+
self.counter=counter+1
5+
self.name=name
6+
self.age=age
7+
8+
def func(self):
9+
return self.counter
10+
def __del__(self):
11+
print("class is destroyed")
12+
s=Students(0,"name",22)
13+
print(s.func())

‎4.multi_inherit.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Person:
2+
def define(self,name,age):
3+
self.name=name
4+
self.age=age
5+
print(name)
6+
print(age)
7+
class Student(Person):
8+
def mark(self,marks):
9+
self.marks=marks
10+
print(marks)
11+
s.define("AAyush",22)
12+
class Locality(Student):
13+
def add(self,address):
14+
self.address=address
15+
print(address)
16+
s.mark(69)
17+
s=Locality()
18+
s.add("Tower 15. 704")

‎5.database_connect.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pymysql
2+
db=pymysql.connect("localhost","root","root","studentdb")
3+
cursor=db.cursor()
4+
#cursor.execute("create table marks2(name varchar(20), marks)");
5+
#print("table created successfully")
6+
cursor.execute("insert into marks values ('Satyam1',56)");
7+
cursor.execute("select * from marks");
8+
for i in cursor:
9+
print(i)
10+
cursor.close()
11+

‎6.dml_query.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import pymysql
2+
db=pymysql.connect("localhost","root","root","studentdb")
3+
cursor=db.cursor()
4+
print("table created successfully")
5+
cursor.execute("insert into marks values ('Satyam1',56)");
6+
cursor.execute("select name,mark from marks");
7+
for i in cursor:
8+
print(i)
9+
print("----------------------------")
10+
cursor.execute("UPDATE marks set name ='Aaush' where mark=69")
11+
cursor.execute("select * from marks")
12+
for i in cursor:
13+
print(i)
14+
print("-----------------------------------")
15+
cursor.execute("DELETE from marks where name='Satyam1'")
16+
cursor.execute("select * from marks")
17+
for i in cursor:
18+
print(i)
19+
cursor.close()
20+

‎7.commit_rollback.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pymysql
2+
db=pymysql.connect("localhost","root","root","studentdb")
3+
cursor=db.cursor()
4+
#print("table created successfully")
5+
cursor.execute("insert into marks values ('Satyam1',56)");
6+
cursor.execute("select name,mark from marks");
7+
for i in cursor:
8+
print(i)
9+
print("-------------------------")
10+
db.commit()
11+
12+
cursor.execute("UPDATE marks set name ='Aaush' where mark=69")
13+
cursor.execute("select * from marks")
14+
for i in cursor:
15+
print(i)
16+
print("-------------------------")
17+
cursor.execute("DELETE from marks where name='Aaush'")
18+
cursor.execute("select * from marks")
19+
for i in cursor:
20+
print(i)
21+
db.rollback()
22+
cursor.close()
23+

‎8a.server.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import socket
2+
s=socket.socket()
3+
host=socket.gethostname()
4+
port=12345
5+
s.bind((host,port))
6+
7+
s.listen((5))
8+
while True:
9+
c,addr=s.accept()
10+
print("Got connection from",addr)
11+
c.send(bytes("Thank you for connecting","utf-8"))
12+
c.close()

‎8b.client.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import socket
2+
s=socket.socket()
3+
host = socket.gethostname()
4+
port=12345
5+
6+
s.connect((host,port))
7+
msg=s.recv(1024)
8+
print(msg.decode("utf-8"))
9+
s.close()

‎9.google_socket.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import socket # for socket
2+
import sys
3+
4+
try:
5+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
6+
print("Socket successfully created")
7+
except socket.error as err:
8+
print("socket creation failed with error %s" % (err))
9+
10+
# default port for socket
11+
port = 80
12+
13+
try:
14+
host_ip = socket.gethostbyname('www.google.co.in')
15+
except socket.gaierror:
16+
17+
# this means could not resolve the host
18+
print("there was an error resolving the host")
19+
sys.exit()
20+
21+
# connecting to the server
22+
s.connect((host_ip, port))
23+
24+
print("the socket has successfully connected to google on port == %s" % (host_ip))

‎README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# anagra.py -
2+
function that takes two strings and returns True if they are anagrams and False otherwise.
3+
A pair of strings is anagrams if the letters in one word can be arranged to form the second one.
4+
Test case1: input: listen silent output: True
5+
6+
# fibona.py-
7+
a recursive function to print nth term of the Fibonacci sequence.
8+
9+
# palind.py-
10+
a recursive function to check whether a string is a palindrome.
11+
12+
# facto.py-
13+
a recursive function in Python to find the factorial of a number.
14+
15+
# missi.py-
16+
a program that uses a for loop to"count mississippily" to
17+
five. Having counted to five, the program should print to the screen the final message "Ready or not, here I come!
18+
19+
# whiles.py-
20+
a program that uses a while loop and continuously asks the user to enter a word unless the user enters chupacabra
21+
as the secret exit word, in which case the message You've successfully left the loop. should be printed to the
22+
screen, and the loop should terminate.
23+
# voweleater.py -
24+
ask the user to enter a word;
25+
use conditional execution and the continue statement to eat the following vowels
26+
A, E, I, O, U from the inputted word;
27+
print the uneaten letters to the screen, each one of them on a separate line.
28+
29+
# twolines.py-
30+
Using one of the comparison operators in Python, write a simple two-line program that takes the parameter;
31+
n as input, which is an integer, and prints False if n is less than 100,
32+
and True if n is greater than or equal to 100.
33+
# pyarmid.py-
34+
task is to write a program which reads the number of blocks the builders have, and outputs the height of th
35+
pyramid that can be built using these blocks;
36+
he height is measured by the number of fully completed layers - if the builders don't have a sufficient number
37+
of blocks and cannot complete the next layer, they finish their work immediately.
38+
The pyramid is stacked according to one simple principle: each lower layer contains one block more than the layer
39+
above.
40+
41+
# lineinverse.py-
42+
Reverse the contents of a list without using the reverse() method of a list and without using slicing.
43+
44+
45+
46+
47+

‎anagram.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
a=input()
2+
b=input()
3+
alen=0
4+
blen=0
5+
r=0
6+
for i in a:
7+
alen=alen+1
8+
for i in b:
9+
blen=blen+1
10+
if alen==blen:
11+
for i in a:
12+
for j in b:
13+
if i==j:
14+
r=r+1
15+
if r==alen:
16+
print("True")
17+
else:
18+
print("false")
19+
else:
20+
print("flase")

‎facto.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def factorial(n):
2+
if(n <= 1):
3+
return 1
4+
else:
5+
return(n*factorial(n-1))
6+
n = int(input())
7+
print(factorial(n))

‎fibona.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def fibonacci(n):
2+
a = 0
3+
b = 1
4+
if n == 0:
5+
return a
6+
elif n == 1:
7+
return b
8+
else:
9+
for i in range(2,n):
10+
c = a + b
11+
a = b
12+
b = c
13+
return b
14+
15+
n=int(input())
16+
print(fibonacci(n))

‎list even odd.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def func(lst):
2+
even=0
3+
odd=0
4+
for i in lst:
5+
if i%2==0:
6+
even+=1
7+
else:
8+
odd+=1
9+
return even,odd
10+
mylist=[10,2,34,56,78,34,65,76,23,45,67,90]
11+
e,o=func(mylist)
12+
print("Even={} and Odd={}".format(e,o))

‎listinverse.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def reverse(array):
2+
n = array
3+
first = 0
4+
last = len(array) - 1
5+
while first < last:
6+
holder = n[first]
7+
n[first] = n[last]
8+
n[last] = holder
9+
first += 1
10+
last -= 1
11+
return n
12+
a=int(input())
13+
n=[]
14+
for i in range(a):
15+
b=input()
16+
n.append(b)
17+
print(reverse(n))

‎missi.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import time
2+
for i in range(1,6):
3+
time.sleep(1)
4+
print("Ready or not, here I come!")

‎mysqlconnection.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import mysql.connector
2+
mydb=mysql.connector.connect(host='localhost',user='root',passwd='gameover007',database='queen')
3+
mycursor=mydb.cursor()
4+
mycursor.execute("select * from student")
5+
for i in mycursor:
6+
print(i)

‎palind.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def palin(a):
2+
if len(a)<=1:
3+
return "True"
4+
else:
5+
if a[0]==a[-1]:
6+
return palin(a[1:-1])
7+
else:
8+
return "False"
9+
10+
a=input()
11+
print(palin(a))

‎pyramid.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
blocks = int(input("Enter the number of blocks: "))
2+
3+
height = 0
4+
5+
inlayer = 1
6+
7+
while inlayer <= blocks:
8+
9+
height += 1
10+
blocks -= inlayer
11+
inlayer += 1
12+
13+
print("The height of the pyramid: ", height)

‎twolines.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
a=int(input())
2+
print({True: "True", False:"False"} [a < 100])

‎voweleater.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
a=input()
2+
a=a.upper()
3+
for i in a:
4+
if i!=("A"):
5+
if i!=("E"):
6+
if i!=("I"):
7+
if i!=("O"):
8+
if i!=("U"):
9+
print(i)

‎whiles.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
i=0
2+
while i<1:
3+
a=input()
4+
if a=="chupacabra":
5+
print("You've successfully left the loop")
6+
break;

0 commit comments

Comments
 (0)
Please sign in to comment.