Week 8 Python
Week 8 Python
a. Open IDLE.
b. In the Python shell, type:
import os
os.system('pip install matplotlib')
You can do the same for Scipy:
import os
os.system('pip install numpy scipy')
import numpy as np
# Create a 1D array
arr = np.array([1, 2, 3, 4, 5])
print("Array:", arr)
# Mean and Standard Deviation
print("Mean:", np.mean(arr))
print("Standard Deviation:", np.std(arr))
# 2D array and matrix multiplication
A = np.array([[1, 2], [3, 4]])
B = np.array([[2, 0], [1, 2]])
print("Matrix multiplication:\n", np.dot(A, B))
OUTPUT:
import numpy as np
import matplotlib.pyplot as plt
# Simple Line Plot
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y, label='sin(x)')
plt.title("Sine Wave")
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.legend()
plt.grid(True)
plt.show()
OUTPUT:
Use: Built on NumPy. Supports optimization, integration, interpolation, statistics, and more.
3. Write a program to implement Digital Logic Gates – AND, OR, NOT, EX-OR
#Function for AND Gate
def AND(A, B):
return A & B
print("AND LOGIC OUTPUT")
print("Output of 0 AND 0 is:", AND(0, 0))
print("Output of 0 AND 1 is:", AND(0, 1))
print("Output of 1 AND 0 is:", AND(1, 0))
print("Output of 1 AND 1 is:", AND(1, 1))
print("**************************************")
print(" Half adder OUTPUT")
print("Output of sum and carry is:", half_adder(0, 0))
print("Output of sum and carry is:", half_adder (0, 1))
print("Output of sum and carry is:", half_adder (1, 0))
print("Output of sum and carry is:", half_adder (1, 1))
OUTPUT:
print("**************************************")
print(" XOR LOGIC OUTPUT")
print("**************************************")
print("**************************************")
OUTPUT:
5. Write a GUI program to create a window wizard having two text labels, two text fields and
two buttons as Submit and Reset.
OUTPUT: