0% found this document useful (0 votes)
3 views3 pages

Python Practical 5 Codes

The document contains four separate code snippets demonstrating various functionalities in Python. Code 5-A retrieves and formats the current date, Code 5-B prints calendars for specific months and years, Code 5-C compares two dates, and Code 5-D showcases the creation and manipulation of NumPy arrays. Each section includes example usage to illustrate the functionality.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Python Practical 5 Codes

The document contains four separate code snippets demonstrating various functionalities in Python. Code 5-A retrieves and formats the current date, Code 5-B prints calendars for specific months and years, Code 5-C compares two dates, and Code 5-D showcases the creation and manipulation of NumPy arrays. Each section includes example usage to illustrate the functionality.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

""" #Code for 5-A

from datetime import datetime,timezone


#Get current local timestamp
timestamp= [Link]().timestamp()
print(timestamp)

#convert to datetime object


date_time=[Link](timestamp)

#format as a string (YYYY-MM-DD)


date_only=date_time.strftime("%Y-%m-%d")

print(f"Timestamp:{timestamp}")
print(f"Date:{date_only}")"""

""" #Code for 5-B


import calendar
#Function to print the calendar for a specific month
def print_month_calendar(year,month):
#Create a TextCalendar instance
cal = [Link]([Link])
#Use the formatmonth to get a multiline string representing the month's calendar
month_calendar = [Link](year,month)
print(f"---Calendar for {calendar.month_name[month]} {year}---\n")
print(month_calendar)

#Function to print the calendar for an entire year


def print_year_calendar(year):
#Use prcal to print thr calendar for a whole year directly to the console
print(f"---Calendar for the year {year}---\n")
[Link](year)

#Example usage:
year_to_use = 2025
month_to_use = 12

#Print December 2025 calendar


print_month_calendar(year_to_use, month_to_use)
#Print the entire 2025 calendar
print_year_calendar(year_to_use)"""

""" #Code for 5-C


from datetime import date
#Function to compare two dates
def compare_dates(date1,date2):
print(f"Date 1:{date1}")
print(f"Date 2:{date2}")

if date1 == date2:
print("Result: Both dates are the same.")
elif date1<date2:
print("Result: Date 1 is earlier than Date 2.")
else:
print("Result: Date 1 is later than Date 2.")

#Example Usage:
#Create date objects using the date(year,month,day) constructor
date_today = [Link]()
date_future = date(2026, 1, 15)
date_past = date(2024, 5, 20)

#Comparing today's date with the future date


compare_dates(date_today, date_future)
print("-" * 30)

#Comparing today's date with the past date


compare_dates(date_today, date_past)"""

""" #Code for 5-D


import numpy as np

#[Link] a NumPy array from a python list


list_data = [10, 20, 30, 40, 50]
numpy_array = [Link](list_data)

print(f"From list: {numpy_array}")


print(f"Type: {type(numpy_array)}")
print(f"Shape: {numpy_array.shape}\n")

#[Link] a 2D array from a list of lists(matrix)


matrix_data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
numpy_array_2d = [Link](matrix_data)

print(f"From list of lists(2D):\n{numpy_array_2d}")


print(f"Shape: {numpy_array_2d.shape}\n")

#[Link] built in NumPy functions for array creation


#create an array of zeros
zeros_array = [Link]((2, 3)) #2 rows, 3 columns
print(f"Zero array: \n{zeros_array}\n")

#Create an array with random values


random_array = [Link](2, 2) #2x2 array of random floats in [0, 1)
print(f"Random Array: \n{random_array}")"""

You might also like