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

Remaining Assignment X1

The document contains four assignments related to programming tasks. Assignment 12 counts the occurrences of a specific element in a list, Assignment 13 separates a list of integers into positive and negative lists, Assignment 14 calculates the mean, median, and mode of a dataset using Numpy, and Assignment 15 displays a line chart using Matplotlib. Each assignment includes a problem statement, code, and expected output.

Uploaded by

eggos7273
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)
4 views2 pages

Remaining Assignment X1

The document contains four assignments related to programming tasks. Assignment 12 counts the occurrences of a specific element in a list, Assignment 13 separates a list of integers into positive and negative lists, Assignment 14 calculates the mean, median, and mode of a dataset using Numpy, and Assignment 15 displays a line chart using Matplotlib. Each assignment includes a problem statement, code, and expected output.

Uploaded by

eggos7273
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/ 2

Assignment: 12

Problem Statement:
Find the number of times an element occurs in the list.

Code:
data = [10, 20, 20, 30, 40, 50, 50, 50]
target = 50
count = data.count(target)

print(f"The element {target} occurs {count} times in the list.")

Output:

The element 50 occurs 3 times in the list.


Assignment: 13

Problem Statement:

Read a list of n integers (positive and negative). Create two new list, one having all the positive and other
having all negative numbers from that list. Display all 3 list.

Code:

n = int(input("Enter the number of integers: "))


original_list = [int(input(f"Enter integer {i+1}: ")) for i in range(n)]

positive_list = [x for x in original_list if x > 0]

negative_list = [x for x in original_list if x < 0]


print("Original List:", original_list)

print("Positive List:", positive_list)

print("Negative List:", negative_list)


Output:

Enter the number of integers: 5

Enter integer 1: 3

Enter integer 2: -7

Enter integer 3: 10
Enter integer 4: -2

Enter integer 5: 0

Original List: [3, -7, 10, -2, 0]

Positive List: [3, 10]

Negative List: [-7, -2]

Assignment: 14

Problem Statement:
Calculate mean median and mode using Numpy.
Code:
import numpy as np
data = [10,20,30,40,50,50,50]

print("Mean:", np.mean(data))
print("Median:", np.median(data))
mode = max(set(data), key=data.count)
print("Mode:",mode)

Output:

Mean: 35.71

Median: 40.0
Mode: 50

Assignment: 15

Problem Statement:

Display line chart from (2,5) to (9,10).


Code:

import matplotlib.pyplot as plt

x = [2, 3, 4, 5, 6, 7, 8, 9]
y = [5 + (10 - 5) * (i - 2) / (9 - 2) for i in x]

plt.plot(x, y, marker='o', linestyle='-', color='blue', label="Line Chart")

plt.title("Line Chart from (2, 5) to (9, 10)")

plt.xlabel("X-axis")
plt.ylabel("Y-axis")

plt.legend()

plt.grid()
plt.show()

Output:

You might also like