0% found this document useful (0 votes)
14 views2 pages

Python Basic Math and List Operations

The document contains a series of Python programming exercises that cover basic operations such as finding squares, sums, and averages, as well as more complex tasks like list manipulation and conditional statements. Each exercise includes a brief description and the corresponding code snippet. The exercises are designed to help users practice and enhance their programming skills.

Uploaded by

funnybutwhyy
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)
14 views2 pages

Python Basic Math and List Operations

The document contains a series of Python programming exercises that cover basic operations such as finding squares, sums, and averages, as well as more complex tasks like list manipulation and conditional statements. Each exercise includes a brief description and the corresponding code snippet. The exercises are designed to help users practice and enhance their programming skills.

Uploaded by

funnybutwhyy
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

1. Find the square of a number entered by the user.

num = int(input("Enter a number: ")) print("Square =", num * num)


2. Find the sum of two numbers entered by the user.
a = int(input("Enter first number: ")) b = int(input("Enter second number: "))
print("Sum =", a + b)
3. Convert length in kilometre to metres.
km = float(input("Enter length in km: ")) print("Metres =", km * 1000)
4. Print table of a number up to five terms.
n = int(input("Enter a number: ")) for i in range(1, 6): print(n, "x", i, "=", n*i)
5. Calculate Simple Interest.
p = float(input("Enter principal: ")) r = float(input("Enter rate: ")) t =
float(input("Enter time: ")) si = (p * r * t) / 100 print("Simple Interest =", si)
6. Calculate average marks of 3 subjects.
m1 = float(input("Enter marks 1: ")) m2 = float(input("Enter marks 2: ")) m3 =
float(input("Enter marks 3: ")) avg = (m1 + m2 + m3) / 3 print("Average =", avg)
7. Calculate area of a triangle.
b = float(input("Enter base: ")) h = float(input("Enter height: ")) area = 0.5 * b *
h print("Area =", area)
8. Surface area and volume of a cuboid.
l = float(input("Enter length: ")) b = float(input("Enter breadth: ")) h =
float(input("Enter height: ")) tsa = 2 * (l*b + b*h + l*h) vol = l * b * h
print("Surface Area =", tsa) print("Volume =", vol)
9. Check whether a character is vowel or consonant.
ch = input("Enter a character: ").lower() if ch in 'aeiou': print("Vowel") else:
print("Consonant")
10. Display grade based on percentage.
p = float(input("Enter percentage: ")) if p >= 90: print("Grade A") elif p >= 75:
print("Grade B") elif p >= 50: print("Grade C") else: print("Grade D")
11. Find largest among three numbers.
a = int(input("Enter first number: ")) b = int(input("Enter second number: ")) c =
int(input("Enter third number: ")) print("Largest =", max(a, b, c))
12. Numbers divisible by 7 and multiple of 5 (1600–2800).
for i in range(1600, 2801): if i % 7 == 0 and i % 5 == 0: print(i)
13. Display 10 natural numbers in reverse order.
for i in range(10, 0, -1): print(i)
14. Print first 10 even numbers.
for i in range(2, 21, 2): print(i)
15. Print sum of first 10 natural numbers.
print(sum(range(1, 11)))
16. Sum of squares of first 100 natural numbers.
s = 0 for i in range(1, 101): s += i*i print(s)
17. List operations on students list.
students = ["Anaya", "Raj", "Rohit", "Isha", "Kartik", "Sonal", "Preet"]
print(students) [Link]("Isha") [Link]("Jay") [Link](1)
print(students)
18. Operations on list num.
num = [23, 34, 45, 56, 67, 78] print(len(num)) print(num[1:4]) print(num[-4:-1])
19. Modify list based on odd/even.
l1 = [23,24,25,26,27,28,29,30] new = [] for i in l1: if i % 2 == 0: [Link](i +
10) else: [Link](i + 5) print(new)
20. Delete odd and negative numbers.
L1 = [11, -1, -22, -3, 33, 55, 44, -50, 46, 101] L1 = [i for i in L1 if i > 0 and i %
2 == 0] print(L1)
21. Display odd numbers from list.
lst = [7, 10, 12, 16, 5, 2] for i in lst: if i % 2 != 0: print(i)
22. Nested list indexing output.
L1 = [20,30,40,50,["HI","Python","Platform"],60,70,80] print(L1[4]) print(L1[0:4])
print(L1[4][2]) print(L1[4][2][3:6])
23. First 10 even numbers, add 1.
lst = [i for i in range(2, 21, 2)] lst = [i+1 for i in lst] print(lst)
24. Extend and sort list.
L1 = [10, 20, 30, 40] [Link]([14, 12, 15]) [Link]() print(L1)
25. Find min and max in list.
lst = list(map(int, input("Enter numbers: ").split())) print("Min =", min(lst))
print("Max =", max(lst))

You might also like