0% found this document useful (0 votes)
38 views

Basic Python Programs

Uploaded by

kumaranmahe4
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)
38 views

Basic Python Programs

Uploaded by

kumaranmahe4
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/ 6

Basic Python Programs

1. Odd or Even Checker:

Write a program that takes an integer input from the user and prints whether the
number is odd or even.

python

# Example Input: 4

# Example Output: Even

2. Sum of Natural Numbers:

Write a program to calculate the sum of all natural numbers up to a given number `n`.

python

# Example Input: 5

# Example Output: 15

3. Fahrenheit to Celsius Converter:

Create a program to convert a temperature from Fahrenheit to Celsius.

python

# Example Input: 98.6

# Example Output: 37.0


4. Multiplication Table:

Write a program to print the multiplication table of a given number.

python

# Example Input: 3

# Example Output: 3, 6, 9, 12, 15, 18, 21, 24, 27, 30

5. Simple Interest Calculator:

Calculate the simple interest given the principal amount, rate of interest, and time
period.

python

# Example Input: principal=1000, rate=5, time=3

# Example Output: Simple Interest: 150.0

6. Check Leap Year:

Write a program to check if a given year is a leap year.

python

# Example Input: 2024

# Example Output: Leap Year

7. Factorial of a Number:

Implement a function to find the factorial of a number using iteration.


python

# Example Input: 5

# Example Output: 120

8. Reverse a String:

Create a program to reverse a given string.

python

# Example Input: "hello"

# Example Output: "olleh"

9. Find Maximum and Minimum:

Write a program that takes a list of numbers as input and prints the maximum and
minimum values.

python

# Example Input: [3, 1, 4, 1, 5, 9]

# Example Output: Max: 9, Min: 1

10. Count Vowels in a String:

Write a program to count the number of vowels in a given string.

python

# Example Input: "example"

# Example Output: 3
11. Fibonacci Sequence:

Write a program to print the first `n` numbers in the Fibonacci sequence.

python

# Example Input: 5

# Example Output: [0, 1, 1, 2, 3]

12. Prime Number Checker:

Create a function to check if a number is prime.

python

# Example Input: 7

# Example Output: Prime

13. Palindrome Checker:

Implement a program to check if a given string is a palindrome.

python

# Example Input: "radar"

# Example Output: True

14. Armstrong Number Checker:

Write a function to check if a number is an Armstrong number.

python
# Example Input: 153

# Example Output: True

15. Merge Two Sorted Lists:

Write a program to merge two sorted lists into a single sorted list.

python

# Example Input: [1, 3, 5], [2, 4, 6]

# Example Output: [1, 2, 3, 4, 5, 6]

16. Count Words in a Sentence:

Create a program to count the number of words in each sentence.

python

# Example Input: "Hello world, welcome to Python"

# Example Output: 5

17. Remove Duplicates from List:

Write a function to remove duplicate elements from a list.

python

# Example Input: [1, 2, 2, 3, 4, 4, 5]

# Example Output: [1, 2, 3, 4, 5]


18. Caesar Cipher:

Implement a simple Caesar cipher encryption and decryption program.

python

# Example Input: text="hello", shift=3

# Example Output: "khoor"

19. Matrix Addition:

Write a program to add two matrices of the same size.

python

# Example Input: [[1, 2], [3, 4]], [[5, 6], [7, 8]]

# Example Output: [[6, 8], [10, 12]]

20. Bubble Sort Algorithm:

Implement the bubble sort algorithm to sort a list of numbers in ascending order.

python

# Example Input: [64, 34, 25, 12, 22, 11, 90]

# Example Output: [11, 12, 22, 25, 34, 64, 90]

You might also like