Programming Assignment – Unit 1
Part 1: Learning from Mistakes
a. Printing your name without quotation marks
Explanation:
In Python, text must be enclosed in quotation marks to be recognized as a string. Leaving
out quotation marks results in SyntaxError or NameError.
Code Example:
print("Weslay)
print(Weslay)
b. Difference between * and ** operators
Explanation:
* is multiplication and ** is exponentiation.
Code Example:
print(5 * 3)
print(5 ** 3)
c. Displaying integers like 09
Explanation:
Integers cannot begin with a leading zero in Python. "09" must be treated as a string.
Code Example:
print("09")
d. Difference between type('67') and type(67)
Explanation:
'67' is a string and 67 is an integer.
Code Example:
print(type('67'))
print(type(67))
Part 2: Python Programs
a. Multiply age by 2
Code:
age = 25
result = age * 2
print("Double my age is:", result)
b. Display city, country, and continent
Code:
city = "Nairobi"
country = "Kenya"
continent = "Africa"
print(city, country, continent)
c. Examination schedule
Code:
start_day = "Monday, 2 December 2025"
end_day = "Friday, 13 December 2025"
print(start_day, end_day)
d. Temperature of the day
Code:
temperature = 28
print("Temperature today:", temperature)
Reflection:
The exercises helped me understand Python syntax, variable assignment, data types, and
error handling. By writing and running code, I learned how Python interprets strings,
integers, and operators. These tasks reinforced the importance of debugging and testing
code to understand how inputs produce outputs.
References:
Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press.
Python Documentation (Unix, Windows, Mac)
Reflection on Part 2
In Part 2 of this assignment, I learned how Python handles different types of data, including
integers and strings, and how these are used in basic programs. The first exercise, where
age was multiplied by 2, demonstrated that Python performs arithmetic operations easily
once values are stored in variables. This helped reinforce the concept of variable
assignment and integer operations. The second exercise involved storing and printing text,
which illustrated how Python treats text as strings and how multiple variables can be
displayed using the print() function.
The third exercise, involving the examination schedule, showed that Python can be used to
display organized, readable information, which is similar to how real-world applications
generate messages for users. This demonstrates the importance of correct formatting and
proper variable naming. The fourth exercise, where I displayed the temperature, helped me
understand how Python can represent real-world data. It also reinforced the idea that
computer programs often store and display dynamically changing information.
Overall, these exercises improved my understanding of Python’s basic syntax, data types,
variable usage, and output formatting. They also highlighted the importance of practicing
code execution to catch errors and better understand how Python handles different
instructions.
References (APA 7th Edition)
Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press.
[Link]
Python Software Foundation. (n.d.). Using Python on Unix platforms.
[Link]
Python Software Foundation. (n.d.). Using Python on Windows.
[Link]
Savage, B. (n.d.). Using Python on a Mac. Python Documentation.
[Link]