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

Module1 Python Basics

Uploaded by

preranagharat9
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)
1 views3 pages

Module1 Python Basics

Uploaded by

preranagharat9
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

BSc Data Science - Python Programming

Module 1: Python Basics Programs

Prepared Notes
Even or Odd Program
Explanation: A number is Even if divisible by 2, otherwise it is Odd.
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Sample Output: Input → 4 → Output → Even

Prime Number Program


Explanation: Prime numbers are divisible only by 1 and themselves.
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, num):
if num % i == 0:
print("Not Prime")
break
else:
print("Prime")
else:
print("Not Prime")
Sample Output: Input → 7 → Output → Prime

Factorial Program
Explanation: Factorial of n is product of all numbers from 1 to n.
Iterative Method:
num = int(input("Enter a number: "))
fact = 1
for i in range(1, num+1):
fact *= i
print("Factorial:", fact)
Recursive Method:
def fact(n):
if n == 0:
return 1
else:
return n * fact(n-1)
num = int(input("Enter a number: "))
print("Factorial:", fact(num))
Sample Output: Input → 5 → Output → 120

Palindrome Program
Explanation: A palindrome reads same backward as forward.
text = input("Enter text: ")
if text == text[::-1]:
print("Palindrome")
else:
print("Not Palindrome")
Sample Output: Input → madam → Output → Palindrome

Flowchart Diagrams
■ (Draw the flowcharts for each program in your notebook or attach digitally here)
Previous Year Questions
1. Write a Python program to check if a number is Prime.
2. Explain recursive function with an example of factorial.
3. Write a program to check if a string is palindrome.

Most Important Questions


✔ Difference between Iterative and Recursive methods of factorial.
✔ Explain palindrome with an example.
✔ Write a short note on prime numbers.

You might also like