SIMATS ENGINEERING
SAVEETHA INSTITUTE OF MEDICAL AND TECHNICAL
SCIENCES
CSA0810 – PYTHON PROGRAMMING
LEVEL – I IMPORTANT PROGRAMS
1. Write a Python program to find the factorial of a number.
Program:
n = 5 fact = 1 for i in range(1, n+1): fact = fact * i print(f"Factorial of {n} is {fact}")
Output:
Factorial of 5 is 120
2. Write a Python program to check if a number is a palindrome or not.
Program:
n = 12321 rn = 0 on = n while n > 0: rem = n % 10 rn = rn * 10 + rem n = n // 10 if on ==
rn: print(f"{on} is a Palindrome") else: print(f"{on} is not a Palindrome")
Output:
12321 is a Palindrome 1234 is not a Palindrome
3. Write a Python program to generate the Fibonacci sequence.
Program:
n = 10 f1, f2 = 0, 1 print("Fibonacci Sequence:") for i in range(n): print(f1) f1, f2 = f2, f1 +
f2
Output:
Fibonacci Sequence: 0 1 1 2 3 5 8 13 21 34
4. Write a Python program to calculate the area of a triangle.
Program:
base = 5 height = 3 area = (base * height) / 2 print(f"Base is {base}, Height is {height}")
print(f"Area is {area}")
Output:
Base is 5, Height is 3 Area is 7.5