Midterm Dennis
Midterm Dennis
SIN: 22107409
LECTURER : EB
1|Page
QUESTION 1
a. Python is a popular programming language known for its simplicity and readability. It's like giving clear
instructions to a computer to perform tasks like solving problems, managing data, and creating websites.
Python is easy to learn for beginners and powerful enough for professionals to build complex
applications.
b. Python is incredibly versatile and can be used to build a wide range of applications, such as:
• Web Development: Creating websites and web applications.
• Data Analysis: Analyzing large datasets and creating visual reports.
• Machine Learning: Building predictive models and AI applications.
• Automation: Automating repetitive tasks.
• Software Development: Creating standalone software applications.
• Game Development: Developing games
c. Difference between Local and Global Variables
Local Variables: Variables defined within a function and accessible only within that function.
def my_function():
local_var = 20 # This is a local variable
print(local_var)
my_function()
# local_var is not accessible here
Global Variables: Variables defined outside of functions and accessible from any function within
the same module.
Example of Global variables:
def my_function():
print(global_var)
my_function()
# global_var is accessible here
2|Page
d. 4 python input data types and their examples
• Integer (int): Whole numbers (e.g., 5, 100, -20).
• Float (float): Numbers with decimal points (e.g., 3.14, 0.001, -7.5).
• String (str): Sequences of characters (e.g., "Hello, world!", 'Python is great').
• Boolean (bool): True or False values (e.g., True, False).
e. Below is a code showing a List of Geoinformatics specializations. It is Showing us how we can retrieve
a sub list or elements from our list using indexes.
3|Page
QUESTION 2
ii. FIONA: Fiona is built on top of GDAL, focusing specifically on vector data. It provides a higher-
level interface for interacting with vector datasets, making it easier to read and write features,
attributes, and geometry. Fiona supports a wide range of vector formats and offers features like
spatial indexing and query capabilities.
iii. SHAPELY: Shapely is a pure Python library for performing geometric operations on planar
geometries. It offers functions for creating, manipulating, and analyzing geometric objects like
points, lines, polygons, and multi-geometries. Shapely can be used for tasks such as calculating
distances, intersections, unions, and buffers between geometric features.
iv. GEOPANDAS: GeoPandas combines the power of pandas for data manipulation and analysis with
geospatial capabilities provided by Shapely and GDAL. It extends pandas DataFrames to include a
geometry column, allowing you to store and manipulate geospatial data within a familiar data
structure. GeoPandas provides functions for spatial joins, overlays, and visualizations of geospatial
data.
b. Pseudocode for Converting Angle to Decimal Degrees
#user input
d = int(input("Enter d: "))
m = int(input("Enter m: "))
s = float(input("Enter s: "))
4|Page
decimal_deg = deg + decimal_m + decimal_s
return decimal_d
decimal_d = deg_min_sec_to_decimal(d, m, s)
print(f"The angle in decimal deg is: {decimal_d:.5f}")
def month_in_words(myNum):
months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November",
"December"]
if 1 <= myNum <= 12:
return months[number - 1]
else:
return "Invalid Month"
def divisible_by_3_or_7(number):
if number % 3 == 0 or number % 7 == 0:
return True
else:
return False
5|Page