Python_Assignment_Part1_and_Part2 (1)
Python_Assignment_Part1_and_Part2 (1)
1 and Part 2
Part 1: Theoretical Questions
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)
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.
Explanation:
This uses string concatenation and print formatting to show a date range.
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