Skip to content

Commit 6d3b16b

Browse files
committed
Add initial code examples
0 parents  commit 6d3b16b

775 files changed

Lines changed: 234658 additions & 0 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
__pycache__

classes-objects/main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from user import User
2+
from post import Post
3+
4+
app_user_one = User("[email protected]", "Nana Janashia", "pwd1", "DevOps Engineer")
5+
app_user_one.get_user_info()
6+
7+
app_user_two = User("[email protected]", "James Bond", "supersecret", "Agent")
8+
app_user_two.get_user_info()
9+
10+
new_post = Post("on a secret mission today", app_user_two.name)
11+
new_post.get_post_info()

classes-objects/post.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Post:
2+
def __init__(self, message, author):
3+
self.message = message
4+
self.author = author
5+
6+
def get_post_info(self):
7+
print(f"Post: {self.message} written by {self.author}")

classes-objects/user.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class User:
2+
def __init__(self, user_email, name, password, current_job_title):
3+
self.email = user_email
4+
self.name = name
5+
self.password = password
6+
self.current_job_title = current_job_title
7+
8+
def change_password(self, new_password):
9+
self.password = new_password
10+
11+
def change_job_title(self, new_job_title):
12+
self.current_job_title = new_job_title
13+
14+
def get_user_info(self):
15+
print(f"User {self.name} currently works as a {self.current_job_title}. You can contact them at {self.email}")

days-to-units/days-to-hours.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
calculation_to_units = 24
2+
name_of_unit = "hours"
3+
4+
5+
def days_to_units(num_of_days):
6+
return f"{num_of_days} days are {num_of_days * calculation_to_units} {name_of_unit}"
7+
8+
9+
def validate_and_execute():
10+
try:
11+
user_input_number = int(num_of_days_element)
12+
13+
# we want to do conversion only for positive integers
14+
if user_input_number > 0:
15+
calculated_value = days_to_units(user_input_number)
16+
print(calculated_value)
17+
elif user_input_number == 0:
18+
print("you entered a 0, please enter a valid positive number")
19+
else:
20+
print("you entered a negative number, no conversion for you!")
21+
except ValueError:
22+
print("your input is not a valid number. Don't ruin my program!")
23+
24+
25+
user_input = ""
26+
while user_input != "exit":
27+
user_input = input("Hey user, enter number of days as a comma separated list and I will convert it to hours!\n")
28+
list_of_days = user_input.split(", ")
29+
for num_of_days_element in set(list_of_days):
30+
validate_and_execute()

days-to-units/days-to-units.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
def days_to_units(num_of_days, conversion_unit):
2+
if conversion_unit == "hours":
3+
return f"{num_of_days} days are {num_of_days * 24} hours"
4+
elif conversion_unit == "minutes":
5+
return f"{num_of_days} days are {num_of_days * 24 * 60} minutes"
6+
else:
7+
return "unsupported unit"
8+
9+
10+
def validate_and_execute():
11+
try:
12+
user_input_number = int(days_and_unit_dictionary["days"])
13+
if user_input_number > 0:
14+
calculated_value = days_to_units(user_input_number, days_and_unit_dictionary["unit"])
15+
print(calculated_value)
16+
elif user_input_number == 0:
17+
print("you entered a 0, please enter a valid positive number")
18+
else:
19+
print("you entered a negative number, no conversion for you!")
20+
except ValueError:
21+
print("your input is not a valid number. Don't ruin my program!")
22+
23+
24+
user_input = ""
25+
while user_input != "exit":
26+
user_input = input("Hey user, enter number of days and conversion unit!\n")
27+
days_and_unit = user_input.split(":")
28+
print(days_and_unit)
29+
days_and_unit_dictionary = {"days": days_and_unit[0], "unit": days_and_unit[1]}
30+
print(days_and_unit_dictionary)
31+
print(type(days_and_unit_dictionary))
32+
validate_and_execute()

spreadsheet/main.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import openpyxl
2+
3+
inv_file = openpyxl.load_workbook("inventory.xlsx")
4+
product_list = inv_file["Sheet1"]
5+
6+
products_per_supplier = {}
7+
total_value_per_supplier = {}
8+
products_under_10_inv = {}
9+
10+
for product_row in range(2, product_list.max_row + 1):
11+
supplier_name = product_list.cell(product_row, 4).value
12+
inventory = product_list.cell(product_row, 2).value
13+
price = product_list.cell(product_row, 3).value
14+
product_num = product_list.cell(product_row, 1).value
15+
inventory_price = product_list.cell(product_row, 5)
16+
17+
# calculation number of products per supplier
18+
if supplier_name in products_per_supplier:
19+
current_num_products = products_per_supplier.get(supplier_name)
20+
products_per_supplier[supplier_name] = current_num_products + 1
21+
else:
22+
products_per_supplier[supplier_name] = 1
23+
24+
# calculation total value of inventory per supplier
25+
if supplier_name in total_value_per_supplier:
26+
current_total_value = total_value_per_supplier.get(supplier_name)
27+
total_value_per_supplier[supplier_name] = current_total_value + inventory * price
28+
else:
29+
total_value_per_supplier[supplier_name] = inventory * price
30+
31+
# logic products with inventory less than 10
32+
if inventory < 10:
33+
products_under_10_inv[int(product_num)] = int(inventory)
34+
35+
# add value for total inventory price
36+
inventory_price.value = inventory * price
37+
38+
39+
print(products_per_supplier)
40+
print(total_value_per_supplier)
41+
print(products_under_10_inv)
42+
43+
inv_file.save("inventory_with_total_value.xlsx")

time-till-deadline/main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from datetime import datetime
2+
3+
user_input = input("enter your goal with a deadline separated by colon\n")
4+
input_list = user_input.split(":")
5+
6+
goal = input_list[0]
7+
deadline = input_list[1]
8+
9+
deadline_date = datetime.strptime(deadline, "%d.%m.%Y")
10+
today_date = datetime.today()
11+
time_till = deadline_date - today_date
12+
13+
hours_till = int(time_till.total_seconds() / 60 / 60)
14+
print(f"Dear user! Time remaining for your goal: {goal} is {hours_till} hours")

0 commit comments

Comments
 (0)