-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: md.ja32 <[email protected]>
- Loading branch information
Showing
19 changed files
with
1,230 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']}.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
print("Hello, world!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from functions import square | ||
|
||
print(square(10)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name = input("Name: ") | ||
print(f"Hello, {name}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.