CS 1101-01 - Ay2025-T5 Unit 1
CS 1101-01 - Ay2025-T5 Unit 1
Before beginning, I installed Python 3.10 on Windows following the official guide (Python
Software Foundation, n.d.-a). All code was executed in IDLE.
Output Explanation:
● Omitting the closing quote causes a SyntaxError (EOL while scanning string
literal) because Python reaches the end-of-line without finding a matching delimiter.
● Omitting both quotes makes Python treat Alice as a variable name, leading to a
NameError since no variable Alice exists (Lutz, 2013).
b. * vs. ** Operators
# Code:
>>> 3 * 4
12
>>> 3 ** 4
81
Output Explanation:
Justification:
Python 3 disallows decimal literals with leading zeros to avoid confusion with octal notation. To
specify octal you must use the 0o prefix (e.g., 0o9 is invalid since 9 is out of octal range).
Therefore, you cannot write 09 (Python Software Foundation, 2021).
Explanation:
Note: All code was run on Python 3.10 IDLE (Python Software Foundation, n.d.-b).
a. Multiply Age by 2
# Code:
age = 22
result = age * 2
print("Twice my age is:", result)
# Output:
# Twice my age is: 44
What I Learned:
Multiplying an integer variable by 2 produces another integer. Assigning intermediate results to
variables improves readability and reuse. Printing with a comma automatically inserts a space.
c. Examination Schedule
# Code:
start_date = "2025-07-01"
end_date = "2025-07-15"
print("Exam Schedule:", start_date, "to", end_date)
# Output:
# Exam Schedule: 2025-07-01 to 2025-07-15
What I Learned:
Dates can be handled as strings for simple display. In production, one would use the
datetime module for validation and formatting (e.g., datetime.date objects).
What I Learned:
Retrieving real-time data typically requires HTTP requests to a weather API (e.g.,
OpenWeatherMap) and parsing JSON responses. Because the assignment did not mandate
internet connectivity, I simulated the temperature as a float. This exercise reinforced how
Python distinguishes numeric types: floats support decimals, ints do not. When working with
external data, one must handle potential exceptions—network timeouts, invalid JSON, or
missing fields—using try/except blocks. Additionally, formatting output for end-users often
involves concatenating strings and variables; f-strings (e.g., f"Current temperature in
{city} is {temperature_c} °C") provide a more concise syntax (PEP 498) and were
introduced in Python 3.6. Future enhancements could include converting between Celsius and
Fahrenheit, rounding to a fixed number of decimal places with the round() function, or
localizing units based on user preferences. Through coding these small programs, I gained
practical insight into Python’s data types, error handling needs, and string formatting
capabilities, which form the bedrock of more complex application development.
References
Downey, A. (2015). Think Python: How to think like a computer scientist (2nd ed.). Green Tree
Press. https://greenteapress.com/thinkpython2/thinkpython2.pdf
Python Software Foundation. (n.d.-a). Using Python on Windows.
https://docs.python.org/3/using/windows.html
Python Software Foundation. (n.d.-b). Using Python on Unix platforms.
https://docs.python.org/3/using/unix.html
Python Software Foundation. (2021). What’s New in Python 3.10.
https://docs.python.org/3/whatsnew/3.10.html