Professional Documents
Culture Documents
Python Out Put
Python Out Put
output:
NAME: SHIVAM GORLA COURSE:BCA-G1 SEMESTER:G1
ROLLNO:2221964(67) SUBJECT:PYTHON STUDENTID:220111410
22. wap in python to calculate ethe square of each element in list using map()
Code:
def square(x):
return x * x
if __name__ == "__main__":
numbers = [1, 2, 3, 4, 5]
squared_numbers = list(map(square, numbers))
print("Original list:", numbers)
print("Squared list:", squared_numbers)
output:
NAME: SHIVAM GORLA COURSE:BCA-G1 SEMESTER:G1
ROLLNO:2221964(67) SUBJECT:PYTHON STUDENTID:220111410
23.wap in python to filter out all the negative numbers from the list
Code:
def is_positive(x):
return x >= 0
if __name__ == "__main__":
numbers = [10, -3, 4, -7, 0, 15, -1, 2]
positive_numbers = list(filter(is_positive, numbers))
print("Original list:", numbers)
print("Filtered list (non-negative numbers):", positive_numbers)
output:
NAME: SHIVAM GORLA COURSE:BCA-G1 SEMESTER:G1
ROLLNO:2221964(67) SUBJECT:PYTHON STUDENTID:220111410
24.wap in python to calculate the sum of the odd numbers from 1 to 10 number list using
filter function
Code:
def is_odd(x):
return x % 2 != 0
if __name__ == "__main__":
numbers = list(range(1, 11))
odd_numbers = list(filter(is_odd, numbers))
sum_of_odd_numbers = sum(odd_numbers)
print("Odd numbers:", odd_numbers)
print("Sum of odd numbers:", sum_of_odd_numbers)
output:
NAME: SHIVAM GORLA COURSE:BCA-G1 SEMESTER:G1
ROLLNO:2221964(67) SUBJECT:PYTHON STUDENTID:220111410
output:
NAME: SHIVAM GORLA COURSE:BCA-G1 SEMESTER:G1
ROLLNO:2221964(67) SUBJECT:PYTHON STUDENTID:220111410
26. wap in python to find the position where elements of two numpy arrays x and y are same?
Code:
import numpy as np
if __name__ == "__main__":
x = np.array([1, 2, 3, 4, 5, 6])
y = np.array([0, 2, 3, 1, 5, 7])
same_positions = np.where(x == y)[0]
print("Array x:", x)
print("Array y:", y)
print("Positions where elements are the same:", same_positions)
output: