Skip to content

Commit 6dc2e4f

Browse files
committed
Initial commit
0 parents  commit 6dc2e4f

File tree

298 files changed

+22650
-0
lines changed

Some content is hidden

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

298 files changed

+22650
-0
lines changed

Cheat Sheet.pdf

4.41 MB
Binary file not shown.
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
print(''' Twinkle, twinkle, little star,
2+
How I wonder what you are!
3+
Up above the world so high,
4+
Like a diamond in the sky.
5+
6+
When the blazing sun is gone,
7+
When he nothing shines upon,
8+
Then you show your little light,
9+
Twinkle, twinkle, all the night.
10+
11+
Then the trav'ller in the dark,
12+
Thanks you for your tiny spark,
13+
He could not see which way to go,
14+
If you did not twinkle so.
15+
16+
In the dark blue sky you keep,
17+
And often thro' my curtains peep,
18+
For you never shut your eye,
19+
Till the sun is in the sky.
20+
21+
'Tis your bright and tiny spark,
22+
Lights the trav'ller in the dark:
23+
Tho' I know not what you are,
24+
Twinkle, twinkle, little star.''')
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Done using REPL
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import pyttsx3
2+
engine = pyttsx3.init()
3+
engine.say("Hey I am good")
4+
engine.runAndWait()
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import os
2+
3+
# Select the directory whose content you want to list
4+
directory_path = '/'
5+
6+
# Use the os module to list the directory content
7+
contents = os.listdir(directory_path)
8+
9+
# Print the contents of the directory
10+
print(contents)

Crash Course/Chapter 1/first.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello World")

Crash Course/Chapter 1/module.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import pyjokes
2+
3+
# print("Printing Jokes...")
4+
5+
# This prints a random joke
6+
joke = pyjokes.get_joke()
7+
print(joke)
8+
9+
10+
# so thanks
11+
# that was my program
12+
# another line
13+
# Yet another line
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Programmer:
2+
company = "Microsoft"
3+
def __init__(self, name, salary, pin):
4+
self.name = name
5+
self.salary = salary
6+
self.pin = pin
7+
8+
9+
p = Programmer("Harry", 1200000, 245001)
10+
print(p.name, p.salary, p.pin, p.company)
11+
r = Programmer("Rohan", 1200000, 245001)
12+
print(r.name, r.salary, r.pin, r.company)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Calculator:
2+
def __init__(self, n):
3+
self.n = n
4+
5+
def square(self):
6+
print(f"The square is {self.n*self.n}")
7+
8+
def cube(self):
9+
print(f"The cube is {self.n*self.n*self.n}")
10+
11+
def squareroot(self):
12+
print(f"The squareroot is {self.n**1/2}")
13+
14+
a = Calculator(4)
15+
a.square()
16+
a.cube()
17+
a.squareroot()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Demo:
2+
a = 4
3+
4+
o = Demo()
5+
print(o.a) # Prints the class attribute because instance attribute is not present
6+
o.a = 0 # Instance attribute is set
7+
print(o.a) # Prints the instance attribute because instance attribute is present
8+
print(Demo.a) # Prints the class attribute
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Calculator:
2+
def __init__(self, n):
3+
self.n = n
4+
5+
def square(self):
6+
print(f"The square is {self.n*self.n}")
7+
8+
def cube(self):
9+
print(f"The cube is {self.n*self.n*self.n}")
10+
11+
def squareroot(self):
12+
print(f"The squareroot is {self.n**1/2}")
13+
14+
@staticmethod
15+
def hello():
16+
print("Hello there!")
17+
18+
a = Calculator(4)
19+
a.hello()
20+
a.square()
21+
a.cube()
22+
a.squareroot()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from random import randint
2+
3+
class Train:
4+
5+
def __init__(self, trainNo):
6+
self.trainNo = trainNo
7+
8+
def book(self, fro, to):
9+
print(f"Ticket is booked in train no: {self.trainNo} from {fro} to {to}")
10+
11+
def getStatus(self):
12+
print(f"Train no: {self.trainNo} is running on time")
13+
14+
def getFare(self, fro, to):
15+
print(f"Ticket fare in train no: {self.trainNo} from {fro} to {to} is {randint(222, 5555)}")
16+
17+
18+
t = Train(12399)
19+
t.book("Rampur", "Delhi")
20+
t.getStatus()
21+
t.getFare("Rampur", "Delhi")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from random import randint
2+
3+
class Train:
4+
5+
def __init__(slf, trainNo):
6+
slf.trainNo = trainNo
7+
8+
def book(harry, fro, to):
9+
print(f"Ticket is booked in train no: {harry.trainNo} from {fro} to {to}")
10+
11+
def getStatus(self):
12+
print(f"Train no: {self.trainNo} is running on time")
13+
14+
def getFare(self, fro, to):
15+
print(f"Ticket fare in train no: {self.trainNo} from {fro} to {to} is {randint(222, 5555)}")
16+
17+
18+
t = Train(12399)
19+
t.book("Rampur", "Delhi")
20+
t.getStatus()
21+
t.getFare("Rampur", "Delhi")
22+
23+

Crash Course/Chapter 10/01_class.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Employee:
2+
language = "Py" # This is a class attribute
3+
salary = 1200000
4+
5+
6+
harry = Employee()
7+
harry.name = "Harry" # This is an instance attribute
8+
print(harry.name, harry.language, harry.salary)
9+
10+
rohan = Employee()
11+
rohan.name = "Rohan Roro Robinson"
12+
print(rohan.name, rohan.salary, rohan.language)
13+
14+
# Here name is instance attribute and salary and language are class attributes as they directly belong to the class
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Employee:
2+
language = "Python" # This is a class attribute
3+
salary = 1200000
4+
5+
6+
harry = Employee()
7+
harry.language = "JavaScript" # This is an instance attribute
8+
print(harry.language, harry.salary)
9+

Crash Course/Chapter 10/03_self.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Employee:
2+
language = "Python" # This is a class attribute
3+
salary = 1200000
4+
5+
def getInfo(self):
6+
print(f"The language is {self.language}. The salary is {self.salary}")
7+
8+
@staticmethod
9+
def greet():
10+
print("Good morning")
11+
12+
13+
harry = Employee()
14+
# harry.language = "JavaScript" # This is an instance attribute
15+
harry.greet()
16+
harry.getInfo()
17+
# Employee.getInfo(harry)
18+
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Employee:
2+
language = "Python" # This is a class attribute
3+
salary = 1200000
4+
5+
def __init__(self, name, salary, language): # dunder method which is automatically called
6+
self.name = name
7+
self.salary = salary
8+
self.language = language
9+
print("I am creating an object")
10+
11+
12+
def getInfo(self):
13+
print(f"The language is {self.language}. The salary is {self.salary}")
14+
15+
@staticmethod
16+
def greet():
17+
print("Good morning")
18+
19+
20+
harry = Employee("Harry", 1300000, "JavaScript")
21+
# harry.name = "Harry"
22+
print(harry.name, harry.salary, harry.language)
23+
24+
rohan = Employee()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class TwoDVector:
2+
def __init__(self, i, j):
3+
self.i = i
4+
self.j = j
5+
6+
def show(self):
7+
print(f"The vector is {self.i}i + {self.j}j ")
8+
9+
10+
class ThreeDVector(TwoDVector):
11+
def __init__(self, i, j, k):
12+
super().__init__(i, j)
13+
self.k = k
14+
15+
def show(self):
16+
print(f"The vector is {self.i}i + {self.j}j + {self.k}k")
17+
18+
a = TwoDVector(1, 2)
19+
a.show()
20+
b = ThreeDVector(5, 2, 3)
21+
b.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Animals:
2+
pass
3+
4+
class Pets(Animals):
5+
pass
6+
7+
class Dog(Pets):
8+
9+
@staticmethod
10+
def bark():
11+
print("Bow Bow!")
12+
13+
14+
d = Dog()
15+
16+
d.bark()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Employee:
2+
salary = 234
3+
increment = 20
4+
5+
@property
6+
def salaryAfterIncrement(self):
7+
return (self.salary + self.salary * (self.increment/100))
8+
9+
@salaryAfterIncrement.setter
10+
def salaryAfterIncrement(self, salary):
11+
self.increment = ((salary/self.salary) -1)*100
12+
13+
14+
15+
16+
e = Employee()
17+
# print(e.salaryAfterIncrement)
18+
e.salaryAfterIncrement = 280.8
19+
print(e.increment)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Complex:
2+
def __init__(self, r, i):
3+
self.r = r
4+
self.i = i
5+
6+
def __add__(self, c2):
7+
return Complex(self.r + c2.r, self.i + c2.i)
8+
9+
def __mul__(self, c2):
10+
real_part = self.r * c2.r - self.i * c2.i
11+
imag_part = self.r * c2.i + self.i * c2.r
12+
return Complex(real_part, imag_part)
13+
14+
def __str__(self):
15+
return f"{self.r} + {self.i}i"
16+
17+
18+
19+
c1 = Complex(1, 2)
20+
c2 = Complex(3, 4)
21+
print(c1 + c2)
22+
print(c1*c2)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Vector:
2+
def __init__(self, x, y, z):
3+
self.x = x
4+
self.y = y
5+
self.z = z
6+
7+
def __add__(self, other):
8+
result = Vector(self.x + other.x, self.y + other.y, self.z + other.z)
9+
return result
10+
11+
def __mul__(self, other):
12+
result = self.x * other.x + self.y * other.y + self.z * other.z
13+
return result
14+
15+
def __str__(self):
16+
return f"Vector({self.x}, {self.y}, {self.z})"
17+
18+
# Test the implementation
19+
v1 = Vector(1, 2, 3)
20+
v2 = Vector(4, 5, 6)
21+
v3 = Vector(7, 8, 9) # Same dimension vector
22+
23+
print(v1 + v2) # Output: Vector(5, 7, 9)
24+
print(v1 * v2) # Output: 32
25+
26+
print(v1 + v3) # Output: Vector(8, 10, 12)
27+
print(v1 * v3) # Output: 50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Vector:
2+
def __init__(self, x, y, z):
3+
self.x = x
4+
self.y = y
5+
self.z = z
6+
7+
def __add__(self, other):
8+
result = Vector(self.x + other.x, self.y + other.y, self.z + other.z)
9+
return result
10+
11+
def __mul__(self, other):
12+
result = self.x * other.x + self.y * other.y + self.z * other.z
13+
return result
14+
15+
def __str__(self):
16+
return f"{self.x}i + {self.y}j + {self.z}k"
17+
18+
# Test the implementation
19+
v1 = Vector(1, 2, 3)
20+
v2 = Vector(4, 5, 6)
21+
v3 = Vector(7, 8, 9) # Same dimension vector
22+
23+
print(v1 + v2) # Output: Vector(5, 7, 9)
24+
print(v1 * v2) # Output: 32
25+
26+
print(v1 + v3) # Output: Vector(8, 10, 12)
27+
print(v1 * v3) # Output: 50

0 commit comments

Comments
 (0)