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

Python Solutions Corrected

The document contains a series of Python code snippets demonstrating various programming tasks, including employee salary calculation, pattern generation, prime number checking, HCF and LCM calculation, and more. It also covers array operations using NumPy, data visualization with Matplotlib, and basic file handling with Pandas and OpenCV. Each snippet is designed to illustrate a specific concept or function in Python.

Uploaded by

ajaya.bedi
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)
3 views3 pages

Python Solutions Corrected

The document contains a series of Python code snippets demonstrating various programming tasks, including employee salary calculation, pattern generation, prime number checking, HCF and LCM calculation, and more. It also covers array operations using NumPy, data visualization with Matplotlib, and basic file handling with Pandas and OpenCV. Each snippet is designed to illustrate a specific concept or function in Python.

Uploaded by

ajaya.bedi
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.

Employee Total Salary Calculation


name = input("Enter employee name: ")
age = int(input("Enter age: "))
basic = float(input("Enter basic salary: "))
da = basic * 0.10
hra = basic * 0.10
total = basic + da + hra
print("Total Salary =", total)

2. Pattern Generation
for i in range(1, 6):
print("*" * i)

3. Prime Check
n = int(input("Enter number: "))
for i in range(2, n):
if n % i == 0:
print("Not Prime")
break
else:
print("Prime")

4. HCF and LCM


import math
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
hcf = [Link](a, b)
lcm = (a * b) // hcf
print("HCF:", hcf, "LCM:", lcm)

5. Divisible by 7 and Multiple of 5


for i in range(1200, 2201):
if i % 35 == 0:
print(i)

6. Leap Year
year = int(input("Enter year: "))
if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):
print("Leap Year")
else:
print("Not Leap Year")

7. Palindrome Number
n = input("Enter number: ")
if n == n[::-1]:
print("Palindrome")
else:
print("Not Palindrome")

8. Add Two Lists


l1 = [1, 2, 3]
l2 = [4, 5, 6]
result = [l1[i] + l2[i] for i in range(len(l1))]
print(result)

9. Array Addition & Multiplication


import numpy as np
a = [Link]([1, 2, 3])
b = [Link]([4, 5, 6])
print("Addition:", a + b)
print("Multiplication:", a * b)

10. Array 10 to 100


import numpy as np
arr = [Link](10, 101, 10)
print(arr)

11. 2D Array Random Values


import numpy as np
arr = [Link](0, 20, (2, 3))
print(arr)

12. Max per Row & Column


import numpy as np
arr = [Link](0, 20, (3, 3))
print(arr)
print("Row max:", [Link](axis=1))
print("Column max:", [Link](axis=0))

13. Sort Desc & Sum


import numpy as np
arr = [Link]([10, 3, 6, 8, 2])
print("Sorted (desc):", [Link](arr)[::-1])
print("Sum:", [Link](arr))

14. Mean Median Mode


import numpy as np
arr = [Link]([1, 2, 2, 3, 4])
# Mean
print("Mean:", [Link](arr))
# Median
print("Median:", [Link](arr))
# Mode (manual)
counts = {i: list(arr).count(i) for i in arr}
mode = max(counts, key=[Link])
print("Mode:", mode)

15. Scatter Plot


import [Link] as plt
x = [2, 9, 8, 5, 6]
y = [5, 10, 3, 7, 18]
[Link](x, y)
[Link]()

16. Line Chart


import [Link] as plt
[Link]([2, 9], [5, 10])
[Link]()

17. Read CSV Info


import pandas as pd
df = pd.read_csv("[Link]")
print([Link]())

18. First 5 Records


import pandas as pd
df = pd.read_csv("[Link]")
print([Link]())

19. Read Image


import cv2
img = [Link]("[Link]")
[Link]("Image", img)
[Link](0)
[Link]()

20. Identify Image Shape


import cv2
img = [Link]("[Link]")
print("Shape:", [Link])

You might also like