Skip to content

Commit b8fc644

Browse files
committed
Reinitialize repository
0 parents  commit b8fc644

20 files changed

+2153
-0
lines changed

Base/1.Introduction-to-programming.md

+485
Large diffs are not rendered by default.

Base/2.Data-types-convertion-basic-operations.md

+505
Large diffs are not rendered by default.

Base/3.Conditionals-and-strings.md

+700
Large diffs are not rendered by default.

Base/assets/__init__.py

Whitespace-only changes.

Base/assets/application.log

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2024-05-04 08:00:00 INFO: Application started
2+
2024-05-04 08:05:00 ERROR: Database connection failed
3+
2024-05-04 08:10:00 DEBUG: User authentication successful
4+
2024-05-04 08:15:00 WARNING: Disk space low
5+
2024-05-04 08:20:00 ERROR: Server timeout
6+
2024-05-04 08:25:00 INFO: Application stopped

Base/assets/lesson_12/calculations.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
This modules provides several functions which interact with arithmetical operations between 2 numbers
3+
"""
4+
5+
def add(a, b):
6+
"""Return the sum of a and b."""
7+
return a + b
8+
9+
def subtract(a, b):
10+
"""Return the difference between a and b."""
11+
return a - b
12+
13+
def multiply(a, b):
14+
"""Return the product of a and b."""
15+
return a * b
16+
17+
def divide(a, b):
18+
"""Return the quotient of a divided by b. Raises ValueError on division by zero."""
19+
if b == 0:
20+
raise ValueError("Cannot divide by zero.")
21+
return a / b

Base/assets/lesson_12/greetings.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def say_hello(name):
2+
"""Print a greeting message to the user."""
3+
print(f"Hello, {name}! Welcome to our Python program.")
4+
5+
def say_goodbye(name):
6+
"""Print a goodbye message to the user."""
7+
print(f"Goodbye, {name}! Thanks for using our Python program.")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from processor import open_image, show_image, rotate_image, crop_image
2+
3+
def main():
4+
image_path = input("Enter the path to the image: ")
5+
image = open_image(image_path)
6+
show_image(image)
7+
8+
rotated = rotate_image(image, 90)
9+
show_image(rotated)
10+
11+
cropped = crop_image(image, (100, 100, 400, 400))
12+
show_image(cropped)
13+
14+
if __name__ == "__main__":
15+
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from PIL import Image
2+
3+
def open_image(path):
4+
"""Open and return an image."""
5+
return Image.open(path)
6+
7+
def show_image(image):
8+
"""Display the image."""
9+
image.show()
10+
11+
def rotate_image(image, degrees):
12+
"""Rotate the image by a certain number of degrees."""
13+
return image.rotate(degrees)
14+
15+
def crop_image(image, box):
16+
"""Crop the image to a specific box and return the cropped image."""
17+
return image.crop(box)
Loading

Base/assets/lesson_12/main.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# main.py
2+
3+
import calculations
4+
import greetings
5+
import menu
6+
7+
def main():
8+
greetings.say_hello("User")
9+
menu.display_menu()
10+
11+
while True:
12+
choice = input("Enter your choice: ")
13+
14+
if choice == "1":
15+
name = input("Enter your name: ")
16+
greetings.say_hello(name)
17+
elif choice == "2":
18+
num1 = float(input("Enter the first number: "))
19+
num2 = float(input("Enter the second number: "))
20+
operation = input("Enter the operation (+, -, *, /): ")
21+
22+
if operation == '+':
23+
print("Result:", calculations.add(num1, num2))
24+
elif operation == '-':
25+
print("Result:", calculations.subtract(num1, num2))
26+
elif operation == '*':
27+
print("Result:", calculations.multiply(num1, num2))
28+
elif operation == '/':
29+
try:
30+
print("Result:", calculations.divide(num1, num2))
31+
except ValueError as e:
32+
print(e)
33+
else:
34+
print("Invalid operation. Please choose +, -, *, or /.")
35+
elif choice == "3":
36+
greetings.say_goodbye("User")
37+
break
38+
else:
39+
print("Invalid choice. Please select 1, 2, or 3.")
40+
41+
if __name__ == "__main__":
42+
main()

Base/assets/lesson_12/menu.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# menu.py
2+
3+
def display_menu():
4+
"""Print the main menu options for the application."""
5+
print("Please choose an option:")
6+
print("1. Say Hello")
7+
print("2. Perform a Calculation")
8+
print("3. Exit")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BASE_URL = "http://api.openweathermap.org/data/2.5/weather"
2+
API_KEY = "" # Defne your API_KEY here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Display the data received from API
3+
"""
4+
5+
def display_weather(data):
6+
"""Display the weather information."""
7+
city = data['name']
8+
temp = data['main']['temp']
9+
description = data['weather'][0]['description']
10+
humidity = data['main']['humidity']
11+
12+
print(f"Weather in {city}:")
13+
print(f"Temperature: {temp}°C")
14+
print(f"Condition: {description}")
15+
print(f"Humidity: {humidity}%")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import requests
2+
from constants import BASE_URL, API_KEY
3+
4+
def get_weather_data(city):
5+
"""Fetch weather data for a given city."""
6+
params = {
7+
'q': city,
8+
'appid': API_KEY,
9+
'units': 'metric'
10+
}
11+
response = requests.get(BASE_URL, params=params)
12+
13+
if response.status_code == 200:
14+
return response.json()
15+
else:
16+
response.raise_for_status()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import requests
2+
from assets.lesson_12.request_app.display import display_weather
3+
from assets.lesson_12.request_app.fetch import get_weather_data
4+
5+
def main():
6+
city = input("Enter the name of the city to get the weather for: ")
7+
try:
8+
weather_data = get_weather_data(city)
9+
display_weather(weather_data)
10+
except requests.exceptions.HTTPError as err:
11+
print("HTTP error occurred: ", err)
12+
except requests.exceptions.RequestException as err:
13+
print("Request error occurred: ", err)
14+
15+
if __name__ == "__main__":
16+
main()
129 KB
Loading

Base/images/ascii.png

162 KB
Loading

Base/images/unicode.png

236 KB
Loading

0 commit comments

Comments
 (0)