Skip to content

Commit

Permalink
add changes and commit
Browse files Browse the repository at this point in the history
Signed-off-by: md.ja32 <[email protected]>
  • Loading branch information
web-jamil authored Dec 6, 2024
1 parent d115f7b commit 8a10695
Show file tree
Hide file tree
Showing 19 changed files with 1,230 additions and 0 deletions.
674 changes: 674 additions & 0 deletions Medium/adding_spaces_to_a_string.py

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions Medium/airports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
airports = [
{
"name": "Beijing Capital International Airport",
"code": "PEK",
"country": "China"
},
{
"name": "Los Angeles International Airport",
"code": "LAX",
"country": "United States"
},
{
"name": "London Heathrow Airport",
"code": "LHR",
"country": "United Kingdom"
}
]

for airport in airports:
print(f"{airport['name']} ({airport['code']}) is in {airport['country']}.")
8 changes: 8 additions & 0 deletions Medium/classes0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Point:
def __init__(self, x, y):
self.x = x
self.y = y

p = Point(3, 5)
print(p.x)
print(p.y)
24 changes: 24 additions & 0 deletions Medium/classes1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Flight:

def __init__(self, capacity):
self.capacity = capacity
self.passengers = []

def add_passenger(self, name):
if not self.open_seats():
return False
self.passengers.append(name)
return True

def open_seats(self):
return self.capacity - len(self.passengers)


flight = Flight(capacity=3)

people = ["Harry", "Ron", "Hermione", "Ginny"]
for person in people:
if flight.add_passenger(person):
print(f"Added {person} to flight.")
else:
print(f"No available seats for {person}.")
8 changes: 8 additions & 0 deletions Medium/conditions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
x = 10

if x > 0:
print("x is positive")
elif x < 0:
print("x is negative")
else:
print("x is 0")
13 changes: 13 additions & 0 deletions Medium/decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def announce(f):
def wrapper():
print("About to run the function...")
f()
print("Done running the function.")
return wrapper


@announce
def hello():
print("Hello, world!")

hello()
5 changes: 5 additions & 0 deletions Medium/dictionaries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ages = {"Alice": 22, "Bob": 27}
ages["Charlie"] = 30
ages["Alice"] += 1

print(ages)
16 changes: 16 additions & 0 deletions Medium/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import sys

try:
x = int(input("x: "))
y = int(input("y: "))
except ValueError:
print("Error: Invalid input")
sys.exit(1)

try:
result = x / y
except ZeroDivisionError:
print("Error: Cannot divide by 0")
sys.exit(1)

print(f"x / y = {result}")
5 changes: 5 additions & 0 deletions Medium/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def square(x):
return x * x

for i in range(10):
print("{} squared is {}".format(i, square(i)))
1 change: 1 addition & 0 deletions Medium/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello, world!")
13 changes: 13 additions & 0 deletions Medium/lambda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
movies = [
{"title": "Green Book", "year": 2018},
{"title": "The Shape of Water", "year": 2017},
{"title": "Moonlight", "year": 2016},
{"title": "Spotlight", "year": 2015},
{"title": "Birdman", "year": 2014},
{"title": "12 Years a Slave", "year": 2013}
]

movies.sort(key=lambda movie: movie["year"])

for movie in movies:
print("{title} was released in {year}".format(**movie))
14 changes: 14 additions & 0 deletions Medium/lists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# List of names
names = ["Harry", "Ron", "Hermione", "Ginny"]

# Print first name
print(names[0])

# Add a new name
names.append("Draco")

# Sort names alphabetically
names.sort()

# Print list of names
print(names)
6 changes: 6 additions & 0 deletions Medium/loops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
for i in range(5):
print(i)

names = ["Alice", "Bob", "Charlie"]
for name in names:
print(name)
3 changes: 3 additions & 0 deletions Medium/modules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from functions import square

print(square(10))
2 changes: 2 additions & 0 deletions Medium/name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = input("Name: ")
print(f"Hello, {name}")
3 changes: 3 additions & 0 deletions Medium/sequences.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "Alice"
coordinates = (10.0, 20.0)
names = ["Alice", "Bob", "Charlie"]
13 changes: 13 additions & 0 deletions Medium/sets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Create an empty set
s = set()

# Add elements to set
s.add(1)
s.add(3)
s.add(5)
s.add(3)
print(s)

# Remove elemnt from set
s.remove(5)
print(s)
5 changes: 5 additions & 0 deletions Medium/variables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
a = 28
b = 1.5
c = "Hello!"
d = True
e = None
Loading

0 comments on commit 8a10695

Please sign in to comment.