Programming Assignment Unit 1
Programming Assignment Unit 1
Code:
Explanation:
If you leave out one of the quotation marks or both in Python, you will encounter a
`SyntaxError`. This is because Python interprets the text inside the quotes as a string.
Without proper quotation marks, Python cannot determine where the string begins or
ends.
Expected Output:
Code:
result_multiply = 3 * 4 =12
result_exponentiate = 3 ** 2 =9
print(result_multiply, result_exponentiate)
Explanation:
In Python, `*` is the multiplication operator, and `**` is the exponentiation operator. The
`*` operator multiplies two numbers, while the `**` operator raises one number to the
power of another.
c) Displaying an Integer like `09`
Code:
Explanation:
In Python, integers cannot have leading zeros (except for zero itself). If you try to define
a number like `09`, it will raise a `SyntaxError` because it's interpreted as an invalid octal
number.
Expected Output:
Code:
print(type_string, type_integer)
Explanation:
The `type()` function in Python returns the type of an object. In this case, `type('67')`
returns `<class 'str'>` because it’s a string, while `type(67)` returns `<class 'int'>` because
it’s an integer.
Expected Output:
Code:
age = 32
result = age * 2
print(f"{age} * 2 = {result}")
Explanation:
This program multiplies the user’s age by `2` and displays the result in a formatted string.
Code:
country = "Ethiopia"
continent = "Africa"
Explanation:
This program uses string variables to hold location information and displays it in a
Code:
Explanation:
The program stores the start and end dates of an examination schedule in variables and
displays them. This showcases the ability to store and manipulate date strings in Python.
Code:
temperature = 23°C
Explanation:
This program allows for displaying the temperature, showcasing variable assignment and