Python Programming Assignment - Part
1 and Part 2
Part 1: Theoretical Questions
b. Difference between * and ** Operators in Python
In Python, the * operator is used for multiplication or unpacking a list/tuple, while ** is
used for exponentiation or unpacking dictionaries in functions.
Example for arithmetic use:
a=2*3 # Outputs 6
b = 2 ** 3 # Outputs 8
In function calls:
def demo(x, y, z): print(x, y, z)
args = [1, 2, 3]; demo(*args)
kwargs = {'x': 1, 'y': 2, 'z': 3}; demo(**kwargs)
c. Is it possible to display an integer like 09?
No, Python does not allow leading zeros in integer literals. For example, writing x = 09
will raise a SyntaxError.
However, you can display numbers like 9 as '09' using string formatting: print(f"{9:02}").
d. type('67') and type(67)
type('67') returns <class 'str'> because it's a string.
type(67) returns <class 'int'> because it's an integer.
The quotes change how the value is interpreted by Python.
Part 2: Python Programs and Explanations
a. Multiply Age by 2
Code:
age = 16
result = age * 2
print("Double your age is:", result)
Explanation:
This program takes your age and multiplies it by 2. The multiplication operator (*)
performs arithmetic and returns a numeric result.
b. Display Location
Code:
city = "Lusaka"
country = "Zambia"
continent = "Africa"
print("City:", city)
print("Country:", country)
print("Continent:", continent)
Explanation:
This script uses variables to store and print location data. Strings are used to represent
text like names of places.
c. Display Examination Schedule
Code:
start_day = "Monday"
end_day = "Friday"
print("Exams start on", start_day, "and end on", end_day)
Explanation:
This uses string concatenation and print formatting to show a date range.
d. Display Temperature on Assignment Day
Code:
from datetime import date
today = date.today()
temperature = 28
print("Date:", today)
print("Temperature:", temperature, "°C")
Explanation:
The temperature is simulated as 28°C. The program also displays today's date: 2025-04-
18. The 'date' module helps us get the current date from the system.
References
1. Python Software Foundation. (2023). Built-in Functions. Python.org.
https://docs.python.org/3/library/functions.html
2. Real Python. (2023). Python 3’s * and ** Operators: What They Do and How to
Use Them. https://realpython.com/python-kwargs-and-args/
3. W3Schools. (2023). Python Data Types.
https://www.w3schools.com/python/python_datatypes.asp