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

Python Lab Programs

The document contains important Python programs demonstrating various concepts such as recursion for factorial and Fibonacci series, checking even or odd numbers, calculating frequency in a dictionary, and more. It includes examples for functions, multiplication tables, palindrome checks, pattern printing, finding the largest of three numbers, and reversing strings. Each program is presented with code snippets and brief explanations.

Uploaded by

saniyaammm
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 views2 pages

Python Lab Programs

The document contains important Python programs demonstrating various concepts such as recursion for factorial and Fibonacci series, checking even or odd numbers, calculating frequency in a dictionary, and more. It includes examples for functions, multiplication tables, palindrome checks, pattern printing, finding the largest of three numbers, and reversing strings. Each program is presented with code snippets and brief explanations.

Uploaded by

saniyaammm
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

Python Lab Important Programs

1. Factorial using Recursion


def fact(n):
if n == 0:
return 1
return n * fact(n-1)

print(fact(5))

2. Fibonacci Series
def fib(n):
if n <= 1:
return n
return fib(n-1) + fib(n-2)

for i in range(6):
print(fib(i), end=" ")

3. Even or Odd
n = int(input("Enter number: "))
if n % 2 == 0:
print("Even")
else:
print("Odd")

4. Dictionary Frequency
lst = [1,2,2,3,3,3]
freq = {}

for i in lst:
if i in freq:
freq[i] += 1
else:
freq[i] = 1

print(freq)

5. Sum using Function


def add(a, b):
return a + b

print(add(5, 3))

6. Multiplication Table
n = 5
for i in range(1, 11):
print(n, "x", i, "=", n*i)
7. Palindrome Check
s = input("Enter string: ")

if s == s[::-1]:
print("Palindrome")
else:
print("Not Palindrome")

8. Pattern Program
for i in range(1,5):
for j in range(i):
print("*", end=" ")
print()

9. Largest of Three Numbers


a, b, c = 10, 20, 15

if a > b and a > c:


print("A is largest")
elif b > c:
print("B is largest")
else:
print("C is largest")

10. Reverse String


s = "python"
print(s[::-1])

You might also like