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

Untitled 3

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

Untitled 3

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
You are on page 1/ 3

import calendar

year = int(input("Enter year: "))


month = int(input("Enter month: "))
print([Link](year, month))

Enter year: 1999


Enter month: 10

October 1999
Mo Tu We Th Fr Sa Su
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

import datetime
now = [Link]()

print("Current date and time:", now)


print("Current year:", [Link])
print("Month of year:", [Link]("%B"))
print("Week number of year:", [Link]("%U"))
print("Weekday of the week:", [Link]("%A"))
print("Day of year:", [Link]("%j"))
print("Day of month:", [Link])
print("Day of week:", [Link]()) # Monday=0, Sunday=6

Current date and time: 2025-07-26 [Link].997894


Current year: 2025
Month of year: July
Week number of year: 29
Weekday of the week: Saturday
Day of year: 207
Day of month: 26
Day of week: 5

area = lambda r: 3.14159 * r * r


print("Area of circle:", area(5))

Area of circle: 78.53975

def reverse_string(s):
if len(s) == 0:
return ""
return reverse_string(s[1:]) + s[0]

print("Reversed:", reverse_string("Python"))
Reversed: nohtyP

def power(x, y):


return x ** y

print("Result:", power(2, 5))

Result: 32

def union_intersection(str1, str2):


set1 = set(str1)
set2 = set(str2)
print("Union:", set1 | set2)
print("Intersection:", set1 & set2)

union_intersection("hello", "world")

Union: {'h', 'e', 'l', 'd', 'o', 'w', 'r'}


Intersection: {'l', 'o'}

def sum_digits(n):
if n == 0:
return 0
return n % 10 + sum_digits(n // 10)

print("Sum of digits:", sum_digits(1234))

Sum of digits: 10

def generate_evens(n):
for i in range(0, n+1, 2):
yield i

for num in generate_evens(10):


print(num, end=' ')

0 2 4 6 8 10

def fib_gen(n):
a, b = 0, 1
for _ in range(n):
yield a
a, b = b, a + b

for num in fib_gen(7):


print(num, end=' ')

0 1 1 2 3 5 8

def cylinder_area(r, h):


return 2 * 3.14 * r * (r + h)
def cuboid_volume(l, b, h):
return l * b * h
print("Cylinder Area:", cylinder_area(3, 5))
print("Cuboid Volume:", cuboid_volume(2, 3, 4))

Cuboid Volume: 24

def convert(num):
print("Binary:", bin(num))
print("Octal:", oct(num))

convert(25)

Binary: 0b11001
Octal: 0o31

def square_dict():
d = {x: x**2 for x in range(1, 21)}
print(d)

square_dict()

{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100,


11: 121, 12: 144, 13: 169, 14: 196, 15: 225, 16: 256, 17: 289, 18:
324, 19: 361, 20: 400}

You might also like