0% found this document useful (0 votes)
6 views4 pages

Python Basics: 10 Essential Programs

The document contains a series of Python programming exercises that cover basic concepts such as adding numbers, checking even or odd, reversing strings, calculating factorials, checking leap years, summing digits, generating Fibonacci series, checking for prime and Armstrong numbers, and counting character frequencies in strings. Each exercise includes code snippets that demonstrate how to implement the respective functionality. These exercises are aimed at beginners to help them practice fundamental programming skills.

Uploaded by

shaji chellayyan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Python Basics: 10 Essential Programs

The document contains a series of Python programming exercises that cover basic concepts such as adding numbers, checking even or odd, reversing strings, calculating factorials, checking leap years, summing digits, generating Fibonacci series, checking for prime and Armstrong numbers, and counting character frequencies in strings. Each exercise includes code snippets that demonstrate how to implement the respective functionality. These exercises are aimed at beginners to help them practice fundamental programming skills.

Uploaded by

shaji chellayyan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

AIVON’25

1. Add Two Numbers

a = int(input("Enter first number: "))

b = int(input("Enter second number: "))

print("Sum =", a + b)

2. Check Even or Odd


num = int(input("Enter a number: "))

if num % 2 == 0:

print("Even number")

else:

print("Odd number")

3. Reverse a String
text = input("Enter a string: ")
print("Reversed string:", text[::-1])

4. Factorial of a Number
num = int(input("Enter a number: "))

fact = 1

for i in range(1, num + 1):

fact *= i

print("Factorial:", fact)
5. Check Leap Year
year = int(input("Enter a year: "))

if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):

print("Leap year")

else:

print("Not a leap year")

6. Sum of Digits
num = int(input("Enter a number: "))

total = 0

while num > 0:

total += num % 10

num //= 10

print("Sum of digits:", total)

7. Fibonacci Series
n = int(input("Enter number of terms: "))

a, b = 0, 1

for i in range(n):

print(a, end=" ")

a, b = b, a + b
8. Check Prime Number
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 Number")

else:

print("Not Prime")

9. Check Armstrong Number


num = int(input("Enter a number: "))

power = len(str(num))

s = sum(int(digit) ** power for digit in str(num))

if num == s:

print("Armstrong number")

else:

print("Not Armstrong number")


10. Character Frequency in a String
text = input("Enter a string: ")

freq = {}

for ch in text:

freq[ch] = [Link](ch, 0) + 1

print("Character frequencies:")

for k, v in [Link]():

print(k, ":", v)

You might also like