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

Python Practical Programs

The document contains practical Python programs that demonstrate various functionalities such as calculating the area of a circle, computing simple interest, checking voting eligibility, and determining if a number is odd or even. It also includes programs for generating the first N odd numbers, creating multiplication tables, summing natural numbers, reversing a number, traversing and performing operations on a list. Each program is presented with code snippets and print statements to display results.

Uploaded by

naman86kumar
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)
2 views

Python Practical Programs

The document contains practical Python programs that demonstrate various functionalities such as calculating the area of a circle, computing simple interest, checking voting eligibility, and determining if a number is odd or even. It also includes programs for generating the first N odd numbers, creating multiplication tables, summing natural numbers, reversing a number, traversing and performing operations on a list. Each program is presented with code snippets and print statements to display results.

Uploaded by

naman86kumar
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

Python Practical Programs

1. Area of a Circle
import math
radius = float(input("Enter the radius of the circle: "))
area = math.pi * radius * radius
print("Area of the circle:", area)

2. Simple Interest
principal = float(input("Enter principal amount: "))
rate = float(input("Enter rate of interest: "))
time = float(input("Enter time in years: "))
simple_interest = (principal * rate * time) / 100
print("Simple Interest:", simple_interest)

3. Eligibility to Vote
age = int(input("Enter your age: "))
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")

4. Check if a Number is Odd or Even


num = int(input("Enter a number: "))
if num % 2 == 0:
print("The number is Even.")
else:
print("The number is Odd.")

5. First N Odd Numbers


N = int(input("Enter N: "))
odd_numbers = [num for num in range(1, N*2, 2)]
print("First", N, "odd numbers:", odd_numbers)

6. Multiplication Table of a Number


N = int(input("Enter a number: "))
for i in range(1, 11):
print(f"{N} x {i} = {N*i}")
7. Sum of N Natural Numbers
N = int(input("Enter N: "))
sum_natural = sum(range(1, N+1))
print("Sum of first", N, "natural numbers:", sum_natural)

8. Reverse of a Number
num = int(input("Enter a number: "))
reverse = int(str(num)[::-1])
print("Reversed Number:", reverse)

9. Traverse a List
L = [1, 2, 3, 4, 5]
for item in L:
print(item)

10. Operations on a List


L = ['Sumit', 'Lakshay', 'Ronak', 'Snehal', 'Aditya']

# Add an element at the end


L.append('NewName')
print("After adding an element:", L)

# Add an element at index 2


L.insert(2, 'InsertedName')
print("After inserting at index 2:", L)

# Delete an element from the beginning


del L[0]
print("After deleting first element:", L)

# Delete the last element


L.pop()
print("After deleting last element:", L)

# Delete ‘Ronak’
L.remove('Ronak')
print("After deleting 'Ronak':", L)

# Sort the list in ascending order


L.sort()
print("After sorting in ascending order:", L)

# Sort the list in descending order


L.sort(reverse=True)
print("After sorting in descending order:", L)

# Delete all elements from the list


L.clear()
print("After deleting all elements:", L)

You might also like