Page 248 - CTS - CSA TP - Volume 2
P. 248
COMPUTER SOFTWARE APPLICATION - CITS
Explanation:
• a is assigned the boolean value True.
• b is assigned the boolean value False.
1 Logical AND (and) Operator:
• logical_and is assigned the result of the logical AND operation between a and b.
• If both a and b are True, then logical_and will be True; otherwise, it will be False.
2. Logical OR (or) Operator:
• logical_or is assigned the result of the logical OR operation between a and b.
• If at least one of a or b is True, then logical_or will be True; otherwise, it will be False.
3. Logical NOT (not) Operator:
• logical_not is assigned the result of the logical NOT operation on a.
• If a is True, then logical_not will be False; if a is False, then logical_not will be True.
TASK 5: Working with dates
Code:
# Example 3: Working with dates
fromdatetime import datetime, timedelta
current_date = datetime.now()
future_date = current_date + timedelta(days=7)
print(“Current Date:”, current_date)
print(“Future Date:”, future_date)
Explanation:
In this example, we are working with dates using the datetime module in Python. Here’s a breakdown of the code:
1 Fromdatetime import datetime, timedelta: This line imports the datetime class and the timedelta class from the
datetime module. The datetime class is used for working with dates and times, and timedelta represents the
difference between two dates or times.
2 Current_date = datetime.now(): This line creates a datetime object representing the current date and time. The
datetime.now() function returns the current date and time.
3 Future_date = current_date + timedelta(days=7): This line calculates a future date by adding a timedelta of 7
days to the current date. The timedelta(days=7) represents a duration of 7 days.
4 Print(“Current Date:”, current_date): This line prints the current date and time.
5 Print(“Future Date:”, future_date): This line prints the calculated future date, which is 7 days ahead of the
current date.
Output:
233
CITS : IT & ITES - Computer Software Application - Exercise 123