Download as pdf or txt
Download as pdf or txt
You are on page 1of 43

Pranjal | 23011P0430

EXPERIMENT-1: Downloading and Installing Python and Modules.


a) Python 3 on linux
Aim : To download and install latest version of python on linux.
Software Required :
1. Jupyter Notebook
2. Latest version of python
Procedure :
Installing python on a Linux is usually a straightforward process. Here are the
general steps to install Python on most Linux distributions:
1. Open a Terminal: Open the terminal on your Linux system. You can usually find
it in your application menu or by searching for “Terminal”

2. Update Package Lists: It’s a good practice to update your system’s package
lists before installing new software. Run the following command:
sudo apt update
3. Install Python:
For Python 3: Most modern Linux distributions come with Python 3 preinstalled.
To install latest version of Python 3, use the following command:
sudo apt install python 3
4. Verify Installation: After the installation is complete, you can verify it by
checking the installed version. Run the following command:
python3 –version

1|P a ge
Pranjal | 23011P0430

5. Installing pip(Python Package Manager): pip is a package manager that allows


you to easily install Python libraries with Python, but if not you can still install
using the following command:
sudo apt install python 3-pip

6. Verify pip Installation: After installing pip ,you can verify it by checking the
version. Run the following command:
pip3 –version
That’s it! You’ve successfully installed Python on your Linux system. Keep in mind
that the exact commands might vary slightly depending on your Linux
distributions.
Result: Hence downloaded and installed latest version of python on Linux.

2|P a ge
Pranjal | 23011P0430

b) Python 3 on windows
Aim : To download and install latest version of python on Windows.
Software Required :
1. Jupyter Notebook
2. Latest version of Python
Procedure :
Installing Python 3 on Windows is a straightforward process. Here are the steps:
1. Download Python Installer:
Visit official Python website https//www.python.org/downloads/windows/ and
download the latest version of Python 3 for Windows. Make sure to download the
executable installer that matches your system architecture Usually 32-bit or 6-
bit).
2. Run the Installer:
Once the installer executable is downloaded ,double-click o it to run it. You might
see a security warning; click “Run” or “Yes” to proceed.

3. Installation Options:
- If you choose “Install Now” the installer will proceed to install Python with
default settings. You can skip the next step.
3|P a ge
- If you choose “Customize Installation” you’ll be presented with a list of features.
Ensure that “Add Python to PATH” is checked. This allows you to use Python from
the command prompt without specifying its full path.

5. Complete the Installation:


Click the “Install” button to begin the installation. The installer will copy files to
your sytem. This process
may take a few minutes.
6. Verify Installation:
After the installation is complete you can verify it by opening the Command
Prompt:
-Press ‘Win + R’ to open the Run dialog, type ‘cmd’, and press Enter.
In the Command Prompt, type the following command to check the installed
Python version:
Python –version
7. Install pip (Python Package Manager):
Recent versions of Python come with ‘pip’ pre-installed. However you might need
to update it. To update ‘pip’, use the following command:
Python –m ensurepip –upgrade
After updating ‘pip’, you can use it to install Python 3 on your Windows system.
Result: Hence downloaded and installed latest version of python on Windows.

4|P a ge
Pranjal | 23011P0430

c) pip3 on windows and linux


Aim : To download and install pip3 on Windows and Linux.
Software Required :
1. Jupyter Notebook
2. Latest version of Python
Procedure:
(i) On many Linux distributions, 'pip3' (the package installer for Python 3) comes
installed by default when you install Python 3. However, if it's not already
installed or if you need to upgrade it, you can follow these steps:
1. Open a Terminal: Open the terminal on your Linux system. You can usually find
it in your applications menu or by searching for "Terminal."
2. Update Package Lists (optional but recommended): Before installing or
upgrading packages, it's a good practice to update your system's package lists.
Run the following command:
sudo apt update
(Replace 'apt' with the package manager relevant to your distribution, such as
'yum' for CentOS or Fedora.)
3. Install or Upgrade pip3:
If you have Python 3 installed and pip3 is not present or you want to upgrade it,
use the following command:
sudo apt install python3-pip
4. Verify pip3 Installation: After the installation is complete, you can verify it by
checking the version. Run the following command:
pip3-version
This should display the version number of the installed pip3.
If pip3" is successfully installed or upgraded, you can use it to install P packages
for Python 3 by running commands like 'pip3 install pack name.
(ii) On Windows, Python 3 usually comes with "pip3' (the package installer for
Python 3) pre-installed. However, if for some reason it's not present or you need
to upgrade it, you can follow these steps:

5|P a ge
Pranjal | 23011P0430

1. Check if pip3 is Installed: To check if pip3" is already installed, open Command


Prompt:
-Press 'Win + R' to open the Run dialog, type "cmd", and press Enter.
In the Command Prompt, type the following command:
pip3--version
If pip3' is installed, it will display the version number. If not, you'll need to install
it.
2. Install or Upgrade pip3:
If you have Python 3 installed but 'pip3' is not present or you want to upgrade it,
you can use the following command:
python-m ensurepip-upgrade
This command will ensure that 'pip3' is installed and up-to-date.
If you don't have Python 3 installed, you will need to install it. During the
installation process, make sure to check the "Add Python to PATH" option, which
will also install 'pip3'.
3. Verify pip3 Installation: After the installation or upgrade is complete, you can
verify it by checking the version. Run the following command:
pip3-version
This should display the version number of the installed or upgraded pip3".
If pip3' is successfully installed or upgraded, you can use it to install Python
packages for Python 3 by running commands like 'pip3 install package- name’.
Result: Hence downloaded and installed pip3 on Windows and Linux.

6|P a ge
Pranjal | 23011P0430

d) Install numpy and scipy.


Aim : To install numpy and scipy.
Software Required :
1. Jupyter Notebook
2. Latest version of Python
To install the NumPy and SciPy libraries for Python, you can use the 'pip package
manager. Here are the steps to install both libraries:
1. Open a Terminal or Command Prompt:
-On Linux: Open a terminal.
-On Windows: Press 'Win + R', type 'cmd', and press Enter.
2. Install NumPy:
Run the following command to install the NumPy library:
pip3 install numpy
This command will download and install the NumPy library and its dependencies.

3. Install SciPy:
Run the following command to install the SciPy library:
pip3 install scipy
This command will download and install the SciPy library and its dependencies.

4. *Verify Installation*:
You can verify the installation of NumPy and SciPy by opening a Python
interpreter and importing the libraries:

7|P a ge
- Start a Python interpreter by typing 'python' (or 'python3' on Linux) in the
terminal and pressing Enter.
- Import NumPy and SciPy by typing the following lines one by one and pressing
enter:
python
import numpy
import scipy
If there are no errors, the libraries are successfully installed.

Result: Hence the numpy and scipy are installed performed.

8|P a ge
e) Installing Jupyter Lab:
Aim : To download and install latest version of python on Windows.
Software Required :
1. Jupyter Notebook
2. Latest version of Python
Procedure:
You can install JupyterLab using the Command Prompt in Windows by utilizing the
'pip package manager. Jupyterlab is a powerful interactive development
environment for Jupyter notebooks. Here's how you can install it:
1. Open Command Prompt:
-Press 'Win+ R', type 'cmd', and press Enter to open the Command Prompt.
2. Install JupyterLab:
Run the following command to install JupyterLab using pip":
pip install jupyterlab
This command will download and install JupyterLab and its dependencies.
3. Verify Installation:
After the installation is complete, you can verify it by running the following
command in the Command Prompt:
Jupyter lab --version
This should display the version number of the installed JupyterLab.
4. Start JupyterLab:
Jupyter lab
To start Jupyterlab, run the following command in the Command Prompt:
Result: Hence the JupyterLab is installed performed.

9|P a ge
Pranjal | 23011P0430

EXPERIMENT 2 : Introduction to Python3


a) Printing your biodata on the screen
Aim: To print Biodata on screen.
Software Required:
1. Jupyter Notebook
2. Latest version of Python
Program:
print(" ********* BIO DATA ********** ")
print(" Name : Narahari Yashonandan ")
print(" Father Name : N Ramakrishna ")
print(" Mother Name : N Sravanthi ")
print(" Date of Birth : 18-04-2006 ")
print(" Age : 17 ")
print(" Gender : Male ")
print(" Mobile : 7013212683 ")
print(" Email Id : yashoandannarahari123@gmail.com ")
Output:
********* BIO DATA **********
Name : Narahari Yashonandan
Father Name : N Ramakrishna
Mother Name : N Sravanthi
Date of Birth : 18-04-2006
Age : 17
Gender : Male
Mobile : 7013212683
Email Id : yashoandannarahari123@gmail.com
Result: Hence, Biodata is printed on the screen with input from the user.

10 | P a g e
Pranjal | 23011P0430

b) Printing all the primes less than a given number


Aim: To print the prime numbers less than the given number
Software Required:
1. Jupyter Notebook
2. Latest version of Python
Program:
n=int(input("enter the positive number"))
if n<=1:
print(n,'does not have a prime number')
for num in range(2,n+1):
for i in range(2,num):
if (num%2==0):
break
else:
print(num,end=' ')
Output:
Enter the positive number 7
All prime numbers up to 7 are 2 3 5 7
Result: Hence all the prime numbers less than the entered number have been
printed.

11 | P a g e
Pranjal | 23011P0430

c) Finding all the factors of a number and show whether it is a perfect number,
i.e., the sum
of all its factors (excluding the number itself) is equal to the number itself.
Aim: To print factors of a number and checking whether the number if perfect or
not
Software Required:
1. Jupyter notebook
2. Latest version of Python
Program:
num=int(input("enter the given number"))
sum=0
for i in range (1,num+1):
if (num%i==0):
print(i)
if(i!=num):
sum+=i
if sum==num:
print(num,'is perfect')
else:
print(num,'is not perfect')
Output:
Enter the given number 6
The factors of 6 are
1
2
3
Sum of factors of 6 is 6
Entered number 6 is a perfect number

12 | P a g e
Pranjal | 23011P0430

Result: Hence the factors of a given number have been printed and it is found out
whether the number is a perfect number or not.

13 | P a g e
Pranjal | 23011P0430

EXPERIMENT 3 : Defining and Using Functions


a) Write a function to read data from a file and display it on the screen
Aim: To read and display a file on screen.
Software Required:
1. Jupyter Notebook
2. Latest version of Python
Program:
#function definition
def read_write():
with open('text.txt','w+') as file:
file.write('This is the first function program on python ');
file.write('GNU lab')
with open('text.txt','r') as file:
print(file.read())

#function call
read_write()
Output:
This is the first function program on python GNU lab
Result: Hence, the file is read and displayed on the screen

14 | P a g e
Pranjal | 23011P0430

b) Define a boolean function is palindrome(<input>)


Aim: To check whether string is palindrome or not
Software Required:
1. Jupyter Notebook
2. Latest version of Python
Program:
def is_palindrome(word):
word=word.lower()
if word==word[::-1]:
return True
else:
return False

##call function
word=input('enter the word : ')
if is_palindrome(word):
print(word,'is palindrome')
else:
print(word,'is not palindrome')
Output:
Enter the word : Mahi
Mahi is not palindrome
Result: Hence it is verified with the string is palindrome or not.

15 | P a g e
Pranjal | 23011P0430

c) Write a function collatz(x) which does the following: if x is odd, x = 3x + 1; if x


is even,
then x = x/2. Return the number of steps it takes for x = 1
Aim: To perform n=n/2 if x is even and n=3n+1 if x is odd till n=1 and print number
of steps.
Software Required:
1. Jupyter Notebook
2. Latest version of Python
Program:
def collatz(n):
if n%2==1:
return (3*n)+1
else:
return n//2

#call function
num=int(input('Enter a positive number'))
steps=1
while num!=1:
num=collatz(num)
steps +=1

print('The number of steps taken are:' ,steps)


Output:
Enter a positive number 5
The number of steps taken are: 6
Result: Hence collatz is perfomed.

16 | P a g e
Pranjal | 23011P0430

d) Write a function that computes the Normal distribution.


Aim: To write a function that computes Normal distribution
Software Required:
1. Jupyter Notebook
2. Latest version of Python
Program:
import numpy as np
import matplotlib.pyplot as plt
def nor_distr(m,s):
x=np.linspace(1,100,100)
E = np.exp(-(x-m)**2/(2*s**2))/(np.sqrt(2*np.pi)*s)
plt.plot(x,E)
plt.xlabel('X ')
plt.ylabel('E')
plt.title('Normal distribution')

m=float(input('Enter m value'))
s=float(input('Enter s value, s should be less than m'))
nor_distr(m,s)
Output:
Enter m value 50
Enter s value, s should be less than m 10

17 | P a g e
Pranjal | 23011P0430

Result : Hence a function that computes Normal distribution is written.

18 | P a g e
Pranjal | 23011P0430

EPERIMENT 4 : The package numpy


a) Creating a matrix of given order mxn containing random numbers in the
range 0 to 99999.
Aim : To create matrix of given order and random numbers.
Software Required:
1. Jupyter Notebook
2. Latest version of Python
Program:
import numpy as np
row = int(input('Enter the number of rows: '))
col = int(input('Enter the number of Columns: '))

matrix = np.random.randint(1,1000,size=(row,col))
print(matrix)
Output:
Enter the number of rows: 4
Enter the number of Columns: 5
A matrix of order 4*5 containing random numbers from 1 to 99999 is :
[[ 70 590 614 635 301]
[243 30 974 628 465]
[482 179 9 631 801]
[697 576 566 424 96]]
Result: Hence matrix is created.

19 | P a g e
Pranjal | 23011P0430

b) Write a program that adds, subtracts and multiplies two matrices. Provide an
interface such that, based on the prompt, the function (addition, subtraction or
multiplication) should be performed
Aim: To write a program to perform matrix addition, subtraction or multiplication
based on prompt.
Software Required:
1. Jupyter Notebook
2. Latest version of Python
Program:
import numpy as np
def operator(n,m1,m2):
if n==1:
result=m1+m2
elif n==2:
result=m1-m2
elif n==3:
result=np.dot(m1,m2)
elif n==4:
result =np.dot(m1,np.linalg.inv(m2))
else:
print("invalid operator")
print("result\n")
print(result)
print(""" \t\t\t MENU
1) Add
2)sub
3) mul
4) div
""")
20 | P a g e
Pranjal | 23011P0430

n=int(input('enter a integer to choose operation'))

row1=int(input('enter no.of rows in matrix 1'))


col1=int(input('enter no.of colums in matrix 1'))

matrix1=np.random.randint(1,200,size=(row1,col1))
print(matrix1)
row2=int(input('enter no.of rows in matrix 2'))
col2=int(input('enter no.of colums in matrix 2'))
matrix2=np.random.randint(1,200,size=(row2,col2))
print(matrix2)
if (row1,col1)==(row2,col2):
operator(n,matrix1,matrix2)
else:
print("operation is not possible")
Output:
MENU
1) Add
2)sub
3) mul
4) div

enter a integer to choose operation 1


enter no.of rows in matrix 1 2
enter no.of colums in matrix 1 2
[[197 154]
[ 98 24]]
enter no.of rows in matrix 2 2
21 | P a g e
Pranjal | 23011P0430

enter no.of colums in matrix 2 2


[[ 11 59]
[ 81 126]]
result
[[208 213]
[179 150]]
Result: Hence desired operations is performed.

22 | P a g e
c) Write a program to solve a system of n linear equations in n variables using
matrix inverse.
Aim: To write a program to solve system of n linear equations in n variables.
Software Required:
1. Jupyter Notebook
2. Latest version of Python
Program:
import numpy as np
order=int(input('enter order of matrix'))
matrix1=list(map(int,input('enter elements of A seperated by comma').split(',')))
matrix_A =np.array(matrix1).reshape(order,order)
print('matrix A =\n',matrix_A)
matrix2=list(map(int,input('enter elements of B seperated by comma').split(',')))
matrix_B =np.array(matrix2).reshape(order,1)
print('matrix B =\n',matrix_B)
A_inverse = np.linalg.inv(matrix_A)
X=A_inverse.dot(matrix_B)
print('the solution is X =\n',X)
Output:
enter order of matrix 2
enter elements of A seperated by comma 4,5,6,2
matrix A =
[[4 5]
[6 2]]
enter elements of B seperated by comma 5,6
matrix B =
[[5]
[6]]

23 | P a g e
the solution is X =
[[0.90909091]
[0.27272727]]
Result: Hence a system of n linear equations in n variables is solved using matrix
inversion method.

24 | P a g e
Pranjal | 23011P0430

EXPERIMENT 5 : The package scipy and pyplot.


a) Finding if two sets of data have the same mean value.
Aim : To write a program to check whether two sets of data have same mean
value.
Software Required :
1. Jupyter Notebook
2. Latest version of Python
Program:
import numpy as np
List_A=list(map(int,input("Enter the values of matrix A : ").split(",")))
List_B=list(map(int,input("Enter the values of matrix B : ").split(",")))
print(List_A,'\n',List_B)
A=np.mean(List_A)
B=np.mean(List_B)
print("Mean of A:", A)
print("Mean of B:", B)
if A==B:
print("Both have same mean values")
else:
print("Both have different mean values")
Output:
Enter the values of matrix A : 1,2,3,4
Enter the values of matrix B : 4,3,2,1,4
[1, 2, 3, 4]
[4, 3, 2, 1, 4]
Mean of A: 2.5
Mean of B: 2.8
Both have different mean values

25 | P a g e
Pranjal | 23011P0430

Result: Hence the mean value of two sets of data are found and compared.

26 | P a g e
b) Plotting data read from a file.
Aim : To write a program to plot data read from a file.
Software Required :
1. Jupyter Notebook
2. Latest verion of Python
Program :
import pandas as pd
from matplotlib import pyplot as plt
# filename=input("Enter filename with extension :")
df=pd.read_csv("pytho.csv")
print(df)
figure=plt.figure(figsize=(10,5))
x=df['item']
y=df['unit']
plt.bar(x,y,width=0.4)
plt.xlabel('item')
plt.ylabel('unit')
plt.title('plotting a bar graph')
plt.show()
Output :
item unit
0 apple 300
1 cherry 490
2 banana 250

27 | P a g e
YASHONANDAN | 23011MB608

Result : Hence a the data read from a file is plotted.

28 | P a g e
YASHONANDAN | 23011MB608

d) Plotting a histogram of a given data set.


Aim : To plot a histogram of a given data set.
Software Required :
1. Jupyter Notebook
2. Latest version of Python
Program :
import numpy as np
from matplotlib import pyplot as plt
print("Take random 50 numbers ranging from 1 to 200")
x=np.random.randint(1,200,50)
print(x)
plt.hist(x,edgecolor='black',linewidth=1.2,color='purple',bins=[0,25,50,75,100,125
,150])
plt.title("Histogram")
plt.show()
Output :
Take random 50 numbers ranging from 1 to 200
[151 26 120 45 75 82 39 52 145 100 186 178 130 159 5 60 156 155
116 25 102 142 121 12 175 104 150 123 179 177 132 156 73 193 198 39
97 43 45 109 38 143 115 93 164 57 169 153 9 155]

29 | P a g e
YASHONANADAN | 23011MB608

Result : Hence a histogram is plotted.

30 | P a g e
YASHONANDAN | 23011MB608

EXPERIMENT 6 : The Strings Package


a) Read text from a file and print the number of lines, words and characters.
Aim : To write a program to print the number of lines, words and characters in
from a file.
Software Required :
1. Jupyter Notebook
2. Latest version of Python
Program :
with open('ece.txt', 'r') as file:
text = file.read()
lines = text.split('\n')
num_lines = len(lines)
words = text.split()
num_words = len(words)
num_spaces = text.count(' ')
num_characters = len(text.replace(' ', ''))
print(f"lines: {num_lines} ,words: {num_words} ,spaces: {num_spaces} ,characters
(excluding spaces): {num_characters}")
Output :
lines: 3 ,words: 9 ,spaces: 6 ,characters (excluding spaces): 49
Result : Hence the numbers of lines, words and characters in a file are counted.

31 | P a g e
YASHONANDAN | 23011MB608

b) Read text from a file and return a list of all n letter words beginning with a
vowel.
Aim : To write a program to return a list of all n letter words beginning with a
vowel.
Software Required :
1. Jupyter Notebook
2. Latest version of Python
Program :
filename = input("Enter the file name with extension")
file = open(filename, "r")
vowels= ('A','E','I','O','U','a','e','i','o','u')
matched_words = []
for line in file :
for word in line.split():
if word[0] in vowels:
matched_words.append(word)
print(matched_words)
file.close()
Output :
Enter the file name with extension ece.txt
['is', 'i', 'am', 'engineering']
Result : Hence list of all n letter words starting with a vowel are returned.

32 | P a g e
d) Plot a histogram of words according to their length from text read from a file.
Aim : To plot Normal distribution curve.
Software Required :
1. Jupyter Notebook
2. Latest version of Python
Program :
import matplotlib.pyplot as plt
filename=input('enter filename with extension')
words=[]
words_lengths=[]
with open(filename,"r") as file :
for line in file:
words.extend(line.split())
for word in words:
words_lengths.append(len(word))
print("the list of lengths of words read from file:",words_lengths)
figure=plt.figure(figsize=(10,5))
plt.hist(words_lengths)
plt.title('histogram of words length')
plt.xlabel('length of words')
plt.ylabel('number of words')
plt.xticks(ticks=range(max(words_lengths)+1))
plt.show()
Output :
enter filename with extension ece.txt
the list of lengths of words read from file: [2, 4, 2, 12, 1, 2, 8, 11, 5]

33 | P a g e
YASHONANDAN | 23011MB608

Result : Hence a histogram of words according to their length is plotted.

34 | P a g e
Pranjal | 23011P0430

EXPERIMENT 7 : Installing OS on Raspberry Pi


Aim : Installing OS on Raspberry Pi
Tools Required : A good working computer with windows or linux as the
operating systems(preferably), Raspberry pi model 2,3 or 4, HDMI cable, wired
keyboard, wired mouse, adaptor, c-type charging cable, adaptor.
Procedure:
1. Firstly go the official website of Raspberry pi
(https://www.raspberrypi.com/software/) and install the Raspberry pi imager.
2. Insert a SD card (preferably of 8GB or 16GB) into a SD card reader and connect
it to the computer.
3. Now open the Raspberry pi imager and select the Raspberry рі OS 32 bit and
the SD card of the particular name and go ahead and write it into the SD card.
4. Eject the SD card reader from the computer and remove the SD card from the
raspy.

35 | P a g e
Pranjal | 23011P0430

5. Now insert the SD card in the SD card slot of the raspberry pi.
6. Connect the HDMI cable to the monitor and the Raspberry pi.
7. Connect the keyboard, mouse, and the Ethernet cables.

36 | P a g e
Pranjal | 23011P0430

8. Connect the power source or the adaptor and switch it on.


9. You will be required to login in with username ‘PI’ and password ‘raspberry’ .
10. You must also require ti update the software once it is installed.
Result : Hence Raspbian OS has been installed on Raspberry pi.

37 | P a g e
Pranjal | 23011P0430

EXPERIMENT 8 : Accessing GPIO pins using Python


b) Blinking an LED connected to one of the GPIO pin.
Aim : To perform an experiment on Blinking of an LED connected to one of the
GPIO pin
Software Required :
1. Jupyter notebook
2. Latest version of Python
Program:
import RPI.GPIO as GPIO
import time
ledpin1=11
def main():
for i in Range(5):
print("LED turning on.")
GPIO.output(ledPin1,GPIO.HIGH)
time.sleep(1)
print("LED turning off.")
GPIO.output(ledPin1,GPIO.LOW)
time sleep(0.2)
def setup():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(ledPin1,GPIO.OUT)
GPIO.output(ledPin1,GPIO.LOW)
If_name_ == '_main_'
setup()
main()
GPIO.cleanup()
Output :

38 | P a g e
Pranjal | 23011P0430

Result : Hence an experiment on blinking of a LED is performed.

39 | P a g e
Pranjal | 23011P0430

c) Adjusting the brightness of an LED


Aim : To perform experiment on Adjusting the brightness of an LED
Software Required :
1. Jupyter Notebook
2. Latest version of Python
Program :
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.OUT)
P=GPIO.PMW(11,100)
p.start(0)
while True:
for x in range (0, 20, 1):
p.ChangeDutyCycle(x)
time.sleep(0.1)
for x in range (20, 0, -1):
p.Change Duty Cycle(x)
time.sleep(0.1)
Output :

40 | P a g e
Pranjal | 23011P0430

Result : Hence experiment on Adjusting the Brightness of a LED is performed.

41 | P a g e
EXPERIMENT 9 : Collecting Sensor Data
a) DHT Sensor interface
Aim : To perform an experiment on functioning of DHT Sensor Data.
Software Required :
1. Jupyter Notebook
2. Latest version of Python
Program :
import Adafruit_DHT
import time
DHT_SENSOR = Adafruit_DHT.DHT11
DHT_PIN = 4
while True:
humidity, temperature = Adafruit_DHT.read(DHT_SENSOR, DHT_PIN)
if humidity is not None and temperature is not None:
print("Temp={0:0.1f}C Humidity={1:0.1f}%".format(temperature, humidity))
else:
print("Sensor failure. Check wiring.");
time.sleep(2);
Output :

42 | P a g e
Pranjal | 23011P0430

Result : Hence an experiment on functioning of DHT sensor Data is performed.

43 | P a g e

You might also like