0% found this document useful (0 votes)
36 views188 pages

Week 6

Uploaded by

Vivek Kumar
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)
36 views188 pages

Week 6

Uploaded by

Vivek Kumar
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/ 188

Introduction to Internet of Things

Week 6

Presented By: Riya Tapwal


Under the supervision of

Prof. Sudip Misra

Indian Institute of Technology, Kharagpur, India

IIT Kharagpur Introduction to Internet of Things March 2024 1


Arduino

Programmer > Tools

1.AVRISP mkII: This is a popular external programmer used for burning code onto AVR microcontrollers, which are the
microcontrollers used in most Arduino boards. You would select this option if you have an AVRISP mkII or a compatible
programmer connected to your Arduino board.

2.USBtinyISP: Another external programmer that is compatible with AVR microcontrollers. Select this option if you are using a
USBtinyISP programmer.

3.Arduino as ISP: This option allows you to use one Arduino board as a programmer to upload code to another Arduino board. It's
a useful option for certain advanced projects.

4.Arduino as AVRISP mkII: Similar to the "Arduino as ISP" option, this allows you to use an Arduino board as a programmer,
emulating an AVRISP mkII programmer.

5.Parallel Programmer: This option is used with older Arduino boards that might have a parallel programming header.
6.ArduinoISP: This is a special sketch that you can upload to an Arduino board to turn it into a programmer. You would select this
option when using the Arduino board as a programmer.

7.No Programmer: Use this option if you want to upload code using the bootloader via the USB-to-serial interface. This is the
default and most common choice.
IIT Kharagpur Introduction to Internet of Things Week 6 2
Python

Why python?

 Python is a versatile language which is easy to script and easy to read.


 It doesn’t support strict rules for syntax.
 Its installation comes with integrated development environment for programming.
 It supports interfacing with wide ranging hardware platforms.
 With open-source nature, it forms a strong backbone to build large applications.

Python IDE
 Python IDE is a free and open source software that is used to write codes, integrate several modules and libraries.
 It is available for installation into PC with Windows, Linux and Mac.
 Examples: Spyder, PyCharm, etc.

IIT Kharagpur Introduction to Internet of Things Week 6 3


Python

Data types in python

There are 5 data types in Python:  List


 Numbers x = [10, 10.2, 'python’]
x, y, z = 10, 10.2
 Tuple

 String  Dictionary
x = ‘This is Python’ d = {1:‘item','k':2}
print x >>This is Python
print x[0] >>T
print x[2:4] >>is

IIT Kharagpur Introduction to Internet of Things Week 6 4


Python

Controlling Statements

if (cond.): while (cond.): Break Continue

statement 1 statement 1 for s in "string": for s in "string":


statement 2 statement 2
if s == ‘n’: if s == ‘y’:
elif (cond.):
break continue
statement 1 x = [1,2,3,4]
statement 2 print (s) print (s)
for i in x:
print “End” print “End”
else:
statement 1
statement 2
statement 1
statement 2

IIT Kharagpur Introduction to Internet of Things Week 6 5


Python

Functions in Python

def greater(x, y):

if x > y:

return x, y

else:

return y, x

val = greater(10, 100)


print(val)

Output:: (100,10)

IIT Kharagpur Introduction to Internet of Things Week 6 6


Python

Functions in Python

 Functions can also be assigned and reassigned to the variables.


 Example:

def add (a,b)


return a+b
print (add(4,6))
c = add(4,6)
print c

Output:: 10 10

IIT Kharagpur Introduction to Internet of Things Week 6 7


Python

Variable Scope in Python

Global variables:
These are the variables declared out of any function , but can be accessed inside as well as outside the function.

Local variables:
These are the ones that are declared inside a function.

var = 10
def example(): g_var = 10
var = 100 def example():
print(var) l_var = 100
example() # calling the function print(g_var)
print(var) example() # calling the function

Output:: 100
10 Output:: 10
IIT Kharagpur Introduction to Internet of Things Week 6 8
Python

Modules in Python

Any segment of code fulfilling a particular task that can be used commonly by everyone is termed as a module.

import random
for i in range(1,10):

val = random.randint(1,10)
print (val)

Output:: varies with each execution

IIT Kharagpur Introduction to Internet of Things Week 6 9


Python

Exception Handling in Python

An error that is generated during execution of a program, is termed as exception.


 Syntax:

try: Example:

statements while True:


try:
except _Exception_: n = input ("Please enter an integer: ")
n = int (n)
statements break
except ValueError:
else: print "No valid integer! "
print “It is an integer!"
statements

IIT Kharagpur Introduction to Internet of Things Week 6 10


Python

File Read Write Operations

Opening a File:
 Python allows you to read and write files
 Open() function is used to open a file, returns a file object
 No separate module or library required
open(file_name, mode)
 Three basic steps
 Mode: Four basic modes to open a file
 Open a file
r: read mode
 Read/Write w: write mode
 Close the file a: append mode
r+: both read and write mode

Read from a file:


 read(): Reads from a file Write(): Writes to a file

file=open(‘data.txt’, ‘r’) file=open(‘data.txt’, ‘w’)


file.read() file.write(‘writing to the file’)

IIT Kharagpur Introduction to Internet of Things Week 6 11


Python

File Read Write Operations: Contd…

Closing a file:
 Close(): This is done to ensure that the file is free to use for other resources
file.close()

Using WITH to open a file:


 Good practice to handle exception while file read/write operation
 Ensures the file is closed after the operation is completed, even if an exception is
encountered

IIT Kharagpur Introduction to Internet of Things Week 6 12


Python

Image Read Write Operations: Contd…

Python supports PIL library for image related operations


 Install PIL through PIP

sudo pip install pillow

PIL is supported till python version 2.7. Pillow supports the 3x version of python.

Reading Image in Python:


 PIL: Python Image Library is used to work with image files
from PIL import Image
 Open an image file
image=Image.open(image_name)
 Display the image
image.show()

IIT Kharagpur Introduction to Internet of Things Week 6 13


Python

Image Read Write Operations: Contd…

Convert image to different mode:


 Any image can be converted from one mode to ‘L’ or ‘RGB’ mode

conv_image=image.convert(‘L’)

 Conversion between modes other that ‘L’ and ‘RGB’ needs conversion into any of these 2 intermediate mode

Converting a sample image to Grey Scale

IIT Kharagpur Introduction to Internet of Things Week 6 14


Python

Image Read Write Operations: Contd…

IIT Kharagpur Introduction to Internet of Things Week 6 15


Python

Networking in Python

 Python provides network services for client server model.


 Socket support in the operating system allows to implement clients and servers for both connection-oriented and
connectionless protocols.
 Python has libraries that provide higher-level access to specific application-level network protocols.

IIT Kharagpur Introduction to Internet of Things Week 6 16


WEB SOCKETS

A socket is one endpoint of a two way communication link between two programs running on the
network. The socket mechanism provides a means of inter-process communication (IPC) by establishing
named contact points between which the communication take place.
Types:
▪ Stream Sockets referred as "SOCK_STREAM"
▪ Datagram Sockets referred as "SOCK_DGRAM”
▪ Raw Sockets referred as "SOCK_RAW”

https://beej.us/guide/bgnet/pdf/bgnet_a4_c_1.pdf

IIT Kharagpur Introduction to Internet of Things Week 6 17


USE OF SOCKETS IN PROCESS-TO-PROCESS
COMMUNICATION
▪ Inter-process communication is the mechanism provided by the operating system
that allows processes to communicate with each other.
▪ A pair of processes communicating over a network employs a pair of sockets,
one for each process.

Source: B. A. Forouzan, “ Data Communications and Networking ,”


McGraw-Hill Forouzan Networking Series,5E.

IIT Kharagpur Introduction to Internet of Things Week 6 18


SYSTEM CALLS
▪ The socket() system call is used to create a socket descriptor on both the client
and the server.

▪ bind() system call is used to binds the function with the particular IP and port.

▪ listen() system call hears to the various connections present in the network and
selects the particular client to serve.

▪ The connect() function is then called on the client with three arguments, namely
the socket descriptor, the remote server address and the length of the address
data structure.

▪ Accept() extracts a connection on the buffer of pending connections in the


system.

▪ A send() is used to send the message either from the client to server or vice
versa.

▪ The recv() function is used to receive the messages at the both ends.

▪ The close() call is used to close the connection.

IIT Kharagpur Introduction to Internet of Things Week 6 19


Example

IIT Kharagpur Introduction to Internet of Things Week 6 20


Example

IIT Kharagpur Introduction to Internet of Things Week 6 21


Example

IIT Kharagpur Introduction to Internet of Things Week 6 22


MULTICASTING USING WEB SOCKETS

Sending messages separately to each recipient consumes extra bandwidth and processing time.

Using multicast achieves better efficiency.

Rest the code remains same.


https://pymotw.com/2/socket/multicast.html

IIT Kharagpur Introduction to Internet of Things Week 6 23


Example

Simple client-server program in Python, where the client requests the current time and date from the
server and then prints the same.

IIT Kharagpur Introduction to Internet of Things Week 6 24


Example

IIT Kharagpur Introduction to Internet of Things Week 6 25


Raspberry Pi
What is Raspberry Pi?

• Computer in your palm.


• Low cost.
• Single-board computer.
• Easy to access.

IIT Kharagpur Introduction to Internet of Things Week 6 26


Raspberry Pi

Start up of Raspberry Pi

• Act as both digital output and digital input.


• Output: turn a GPIO pin high or low.
• Input: detect a GPIO pin high or low
IIT Kharagpur Introduction to Internet of Things Week 6 27
Raspberry Pi

Pin Configuration

IIT Kharagpur Introduction to Internet of Things Week 6 28


Raspberry Pi

Set up of Raspberry Pi

• HDMI cable.
• Monitor.
• Key board.
• Mouse.
• 5volt power adapter for raspberry pi.
• LAN cable . Official Supported OS :
• Min- 2GB micro sd card • Raspbian
• NOOBS
Some of the third party OS :
Default installed :
• UBUNTU mate
• Python
• Snappy Ubuntu core
•C
• Windows 10 core
• C++
• Pinet
• Java
• Risc OS
• Scratch
• Ruby

IIT Kharagpur Introduction to Internet of Things Week 6 29


Raspberry Pi OS Setup
Write Raspbian in SD card :
• Install “Win32 Disk Imager” software in windows machine .
• Run Win32 Disk Imager
• Plug SD card into your PC
• Select the “Device”
• Browse the “Image File”(Raspbian image)
• Write

Enable SSH
Step1 : Open command prompt and type sudo raspi-config and
press enter.
Step2: Navigate to SSH in the Advance option.
Step3: Enable SSH

IIT Kharagpur Introduction to Internet of Things Week 6 30


Raspberry Pi OS Setup

IIT Kharagpur Introduction to Internet of Things Week 6 31


Raspberry Pi OS Setup

Expand file system :


Step 1: Open command prompt and type sudo raspi-config and press enter.
Step 2: Navigate to Expand Filesystem
Step 3: Press enter to expand it.

IIT Kharagpur Introduction to Internet of Things Week 6 32


Raspberry Pi

IIT Kharagpur Introduction to Internet of Things Week 6 33


Raspberry Pi

Applications

• Media streamer
• Home automation
• Controlling BOT
• VPN
• Light weight web server for IOT
• Tablet computer

Integration with sensors and actuators


Requirements
 Sensor and actuator interfaced with Raspberry Pi  DHT Sensor
 Read data from the sensor  4.7K ohm resistor
 Control the actuator according to the reading from the  Relay
sensor  Jumper wires
 Connect the actuator to a device  Raspberry Pi
 Mini fan

IIT Kharagpur Introduction to Internet of Things Week 6 34


Raspberry Pi

IIT Kharagpur Introduction to Internet of Things Week 6 35


Question No: 1

What is the output for the following piece of Python code?

x = [32, 'u', 'i', 8, '34']


x = x[0:]
print (x)

a. [32]
b. ['34']
c. ['u', 'i', 8, '34']
d. [32,'u', 'i', 8, '34']

IIT Kharagpur Introduction to Internet of Things Week 6 36


Question No: 1

What is the output for the following piece of Python code?

x = [32, 'u', 'i', 8, '34']


x = x[0:]
print (x)

a. [32]
b. ['34']
c. ['u', 'i', 8, '34']
d. [32,'u', 'i', 8, '34']

IIT Kharagpur Introduction to Internet of Things Week 6 37


Question No: 2

How many GPIO (General Purpose Input Output Pin) pins are there in Raspberry Pi 4?

a. 30
b. 14
c. 40
d. 41

IIT Kharagpur Introduction to Internet of Things Week 6 38


Question No: 2

How many GPIO (General Purpose Input Output Pin) pins are there in Raspberry Pi 4?

a. 30
b. 14
c. 40
d. 41

IIT Kharagpur Introduction to Internet of Things Week 6 39


Question No: 3

Which of the following is NOT an example of Python IDE?

a. Sublime Text
b. PyCharm
c. Spider
d. None of the above

IIT Kharagpur Introduction to Internet of Things Week 6 40


Question No: 3

Which of the following is NOT an example of Python IDE?

a. Sublime Text
b. PyCharm
c. Spider
d. None of the above

Sublime Text, PyCharm, Spyder, and Jupyter are few of the examples of Python IDE.

IIT Kharagpur Introduction to Internet of Things Week 6 41


Question No: 4

What is the value of ‘x’ in the following expression in Python programming?


x = 3^3

a. 0
b. 9
c. -2
d. Will raise an exception

IIT Kharagpur Introduction to Internet of Things Week 6 42


Question No: 4

What is the value of ‘x’ in the following expression in Python programming?


x = 3^3

a. 0
b. 9
c. -2
d. Will raise an exception

 “^” is a bitwise XOR operator in python.

IIT Kharagpur Introduction to Internet of Things Week 6 43


Question No: 5

In python programming, which of the following is a null statement?

a. Pass
b. Continue
c. Break
d. Skip

IIT Kharagpur Introduction to Internet of Things Week 6 44


Question No: 5

In python programming, which of the following is a null statement?

a. Pass
b. Continue
c. Break
d. Skip

As per basics of Python programming, pass is a null operation. The interpreter does not ignore a pass statement, but
nothing happens and the statement results into no operation.

IIT Kharagpur Introduction to Internet of Things Week 6 45


Question No: 6

Which of the following is an unordered data type in Python?

a. List
b. Dictionary
c. Both List and Dictionary
d. Tuple

IIT Kharagpur Introduction to Internet of Things Week 6 46


Question No: 6

Which of the following is an unordered data type in Python?

a. List
b. Dictionary
c. Both List and Dictionary
d. Tuple

IIT Kharagpur Introduction to Internet of Things Week 6 47


Question No: 7

What is the value of ‘x’ in the following expression in Python programming?


x = 2**3^3**1

a. 11
b. 0
c. Will raise an error
d. Will raise an exception

IIT Kharagpur Introduction to Internet of Things Week 6 48


Question No: 7

What is the value of ‘x’ in the following expression in Python programming?


x = 2**3^3**1

a. 11
b. 0
c. Will raise an error
d. Will raise an exception

IIT Kharagpur Introduction to Internet of Things Week 6 49


Question No: 8

Which of the following symbol is used to comment out multiple lines at once in python?

a. $
b. #
c. %
d. None of these

IIT Kharagpur Introduction to Internet of Things Week 6 50


Question No: 8

Which of the following symbol is used to comment out multiple lines at once in python?

a. $
b. #
c. %
d. None of these

Unlike other programming languages Python doesn't support multi-line comment blocks out of the box. The recommended
way to comment out multiple lines of code in Python is to use consecutive # single-line comments.

IIT Kharagpur Introduction to Internet of Things Week 6 51


Question No: 9

With on-board Raspberry Pi camera, which one of the following is NOT correct for image related operations in Python?

a. from PIcamera import PiCamera


b. from picamera import PyCamera
c. from pycamera import PiCamera
d. All of these

IIT Kharagpur Introduction to Internet of Things Week 6 52


Question No: 9

With on-board Raspberry Pi camera, which one of the following is NOT correct for
image related operations in Python?

a. from PIcamera import PiCamera


b. from picamera import PyCamera
c. from pycamera import PiCamera
d. All of these

 the correct statement is “from picamera import PiCamera

IIT Kharagpur Introduction to Internet of Things Week 6 53


Question No: 10

Which of the following bit processor is used in Raspberry Pi Zero 2 W?

a. 64
b. 32
c. Both 64 & 32
d. 128

IIT Kharagpur Introduction to Internet of Things Week 6 54


Question No: 10

Which of the following bit processor is used in Raspberry Pi Zero 2 W?

a. 64
b. 32
c. Both 64 & 32
d. 128

The Raspberry Pi Zero 2 W includes a new Broadcom BCM2710A1 SOC providing a 1GHz quad-core 64-bit ARM
Cortex-A53 CPU and 512MB RAM.

IIT Kharagpur Introduction to Internet of Things Week 6 55


Question No: 11

Which of the following shortcut exits the nano editor?

a. Ctrl + E
b. Ctrl + O
c. Ctrl + X
d. None of these

IIT Kharagpur Introduction to Internet of Things Week 6 56


Question No: 11

Which of the following shortcut exits the nano editor?

a. Ctrl + E
b. Ctrl + O
c. Ctrl + X
d. None of these

Ctrl + O writes the code to a file. Ctrl + X exits the nano editor.

IIT Kharagpur Introduction to Internet of Things Week 6 57


Question No: 12

What of the following syntax is correct for networking in python?

a. s = socket.socket(socket.AF_NET, socket.SOCK_STRAM)
b. s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
c. s = socket.socket(socket.AF_UNX, socket.SOCK_TCP)
d. s = socket.socket(socket.AF_INET, socket.SOCK_UDP)

IIT Kharagpur Introduction to Internet of Things Week 6 58


Question No: 12

What of the following syntax is correct for networking in python?

a. s = socket.socket(socket.AF_NET, socket.SOCK_STRAM)
b. s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
c. s = socket.socket(socket.AF_UNX, socket.SOCK_TCP)
d. s = socket.socket(socket.AF_INET, socket.SOCK_UDP)

AF_UNIX or AF_INET represent socket family. SOCK_STREAM or SOCK_DGRAM represent socket type.

socket_family - AF_UNIX or AF_INET


socket_type - SOCK_STREAM or SOCK_DGRAM
protocol - default ‘0’.

IIT Kharagpur Introduction to Internet of Things Week 6 59


Question No: 13

Which of the following is correct to open a text file for write mode?

a. open('file.txt', ‘w’)
b. open('file.txt', ‘+w’)
c. open('file.txt', ‘w+’)
d. open('file.txt', ‘o+w’)

IIT Kharagpur Introduction to Internet of Things Week 6 60


Question No: 13

Which of the following is correct to open a text file for write mode?

a. open('file.txt', ‘w’)
b. open('file.txt', ‘+w’)
c. open('file.txt', ‘w+’)
d. open('file.txt', ‘o+w’)

‘w’ mode is for writing into a text file. ‘r’ mode is for reading a text file.

IIT Kharagpur Introduction to Internet of Things Week 6 61


Question No: 14

Which of the following is an immutable data type in Python?

a. String
b. Tuple
c. Bool
d. All of these

IIT Kharagpur Introduction to Internet of Things Week 6 62


Question No: 14

Which of the following is an immutable data type in Python?

a. String
b. Tuple
c. Bool
d. All of these

Immutable Objects are of in-built types like int, float, bool, string, unicode, tuple. In simple words, an immutable object
can't be changed after it is created.

IIT Kharagpur Introduction to Internet of Things Week 6 63


Question No: 15

Does python follow rigid indentation?

a. Yes
b. No
c. Not Applicable

IIT Kharagpur Introduction to Internet of Things Week 6 64


Question No: 15

Does python follow rigid indentation?

a. Yes
b. No
c. Not Applicable

IIT Kharagpur Introduction to Internet of Things Week 6 65


Question No: 16

What is the value that is assigned to the variable f in the given piece of python code?

i, f, str=50, 50.68, “Welcome to python”

a. 50
b. 50.68
c. Welcome to python
d. All of these

IIT Kharagpur Introduction to Internet of Things Week 6 66


Question No: 16

What is the value that is assigned to the variable f in the given piece of python code?

i, f, str=50, 50.68, “Welcome to python”

a. 50
b. 50.68
c. Welcome to python
d. All of these

IIT Kharagpur Introduction to Internet of Things Week 6 67


Question No: 17

What is the output of the following piece of python code?

x='17'
y='23'
z=x+y
print(z)

a. 40
b. 6
c. 1723
d. 30

IIT Kharagpur Introduction to Internet of Things Week 6 68


Question No: 17

What is the output of the following piece of python code?

x='17'
y='23'
z=x+y
print(z)

a. 40
b. 6
c. 1723
d. 30

IIT Kharagpur Introduction to Internet of Things Week 6 69


Question No: 18

Fill in the blanks. Raspbian is a/n ___________

a. Microcomputer
b. Minicomputer
c. Operating system
d. Assembler

IIT Kharagpur Introduction to Internet of Things Week 6 70


Question No: 18

Fill in the blanks. Raspbian is a/n ___________

a. Microcomputer
b. Minicomputer
c. Operating system
d. Assembler

IIT Kharagpur Introduction to Internet of Things Week 6 71


Question No: 19

What is the output of the following piece of Python code?


t1 = 'Welcome to python coding'
print(t1[8:14])

a. to pyth
b. SyntaxError: invalid syntax
c. e to pyt
d. to pyt

IIT Kharagpur Introduction to Internet of Things Week 6 72


Question No: 19

What is the output of the following piece of Python code?


t1 = 'Welcome to python coding'
print(t1[8:14])

a. to pyth
b. SyntaxError: invalid syntax
c. e to pyt
d. to pyt

This slice includes all characters from index 8 up to, but not including, index 14. Therefore, the output is the
substring "to pyt", which consists of the characters at indices 8 through 13 of the original string t1.

IIT Kharagpur Introduction to Internet of Things Week 6 73


Question No: 20

Fill in the blanks. Raspberry Pi 3 Model B has a GPU support of _________

a. 400 MHz video core IV


b. 250 MHz video core IV
c. Quad cortex [email protected]
d. ARM 11 @ 1 GHz

IIT Kharagpur Introduction to Internet of Things Week 6 74


Question No: 20

Fill in the blanks. Raspberry Pi 3 Model B has a GPU support of _________

a. 400 MHz video core IV


b. 250 MHz video core IV
c. Quad cortex [email protected]
d. ARM 11 @ 1 GHz

IIT Kharagpur Introduction to Internet of Things Week 6 75


Question No: 21

Which of the following represents the command used for rebooting Raspberry Pi?

a. sudo reboot
b. sudo apt-get rebooting
c. pip install rebooting
d. All of these

IIT Kharagpur Introduction to Internet of Things Week 6 76


Question No: 21

Which of the following represents the command used for rebooting Raspberry Pi?

a. sudo reboot
b. sudo apt-get rebooting
c. pip install rebooting
d. All of these

IIT Kharagpur Introduction to Internet of Things Week 6 77


Question No: 22

State whether true or false.


It is not possible to return multiple values from a function in Python.

a. True
b. False

IIT Kharagpur Introduction to Internet of Things Week 6 78


Question No: 22

State whether true or false.


It is not possible to return multiple values from a function in Python.

a. True
b. False

IIT Kharagpur Introduction to Internet of Things Week 6 79


Question No: 23

What is the data type of the variable ls in the following piece of Python code?
ls= {1: "item", "key": "21", "year": 2022}

a. dictionary
b. list
c. tuple
d. All of these

IIT Kharagpur Introduction to Internet of Things Week 6 80


Question No: 23

What is the data type of the variable ls in the following piece of Python code?
ls= {1: "item", "key": "21", "year": 2022}

a. dictionary
b. list
c. tuple
d. All of these

IIT Kharagpur Introduction to Internet of Things Week 6 81


Question No: 24

State whether true or false.


A function in Python may or may not return a value.

a. True
b. False

IIT Kharagpur Introduction to Internet of Things Week 6 82


Question No: 24

State whether true or false.


A function in Python may or may not return a value.

a. True
b. False

IIT Kharagpur Introduction to Internet of Things Week 6 83


Question No: 25

What are the basic modes to open a file in python?

a. Read mode (r) and write mode (w)


b. Append mode (a)
c. Both read and write mode (r+)
d. All of these

IIT Kharagpur Introduction to Internet of Things Week 6 84


Question No: 25

What are the basic modes to open a file in python?

a. Read mode (r) and write mode (w)


b. Append mode (a)
c. Both read and write mode (r+)
d. All of these

IIT Kharagpur Introduction to Internet of Things Week 6 85


Question No: 26

What are the socket types that exist in Python based socket programming?

a. AF_DG and SOCK_SM


b. AF_UNIX and AF_INET
c. SOCK_UX and SOCK_IT
d. SOCK_DGRAM and SOCK_STREAM

IIT Kharagpur Introduction to Internet of Things Week 6 86


Question No: 26

What are the socket types that exist in Python based socket programming?

a. AF_DG and SOCK_SM


b. AF_UNIX and AF_INET
c. SOCK_UX and SOCK_IT
d. SOCK_DGRAM and SOCK_STREAM

IIT Kharagpur Introduction to Internet of Things Week 6 87


Question No: 27

Does Python support exception handling?

a. Yes
b. No

IIT Kharagpur Introduction to Internet of Things Week 6 88


Question No: 27

Does Python support exception handling?

a. Yes
b. No

IIT Kharagpur Introduction to Internet of Things Week 6 89


Question No: 28

Which of the following must be used to terminate a loop and move to the next code after the loop?

a. list
b. try
c. continue
d. break

IIT Kharagpur Introduction to Internet of Things Week 6 90


Question No: 28

Which of the following must be used to terminate a loop and move to the next code after the loop?

a. list
b. try
c. continue
d. break

IIT Kharagpur Introduction to Internet of Things Week 6 91


Question No: 29

Select the option that does not represent a keyword in Python language?

a. while
b. if
c. try
d. integer

IIT Kharagpur Introduction to Internet of Things Week 6 92


Question No: 29

Select the option that does not represent a keyword in Python language?

a. while
b. if
c. try
d. integer

IIT Kharagpur Introduction to Internet of Things Week 6 93


Question No: 30

Raspberry Pi does not support any other language other than Python?

a. True
b. False

IIT Kharagpur Introduction to Internet of Things Week 6 94


Question No: 30

Raspberry Pi does not support any other language other than Python?

a. True
b. False

IIT Kharagpur Introduction to Internet of Things Week 6 95


Question No: 31

Python’s installation comes with integrated development environment for programming.

True
False

IIT Kharagpur Introduction to Internet of Things Week 6 96


Question No: 31

Python’s installation comes with integrated development environment for programming.

True
False

IIT Kharagpur Introduction to Internet of Things Week 6 97


Question No: 32

Fill in the blanks. Python IDE is available for installation into PC with __________.

Windows
Linux
Mac
All of these

IIT Kharagpur Introduction to Internet of Things Week 6 98


Question No: 32

Fill in the blanks. Python IDE is available for installation into PC with __________.

Windows
Linux
Mac
All of these

IIT Kharagpur Introduction to Internet of Things Week 6 99


Question No: 33

Is relay a type of mechanical switch?

No
Yes

IIT Kharagpur Week 6 10


Introduction to Internet of Things
0
Question No: 33

Is relay a type of mechanical switch?

No
Yes

IIT Kharagpur Week 6 10


Introduction to Internet of Things
1
Question No: 34

How many data type/s are available in Python.

1
2
5
7

IIT Kharagpur Week 6 10


Introduction to Internet of Things
2
Question No: 34

How many data type/s are available in Python.

1
2
5
7

IIT Kharagpur Week 6 10


Introduction to Internet of Things
3
Question No: 35

The variable that is declared inside the function in Python is called a Global variable.

True
False

IIT Kharagpur Week 6 10


Introduction to Internet of Things
4
Question No: 35

The variable that is declared inside the function in Python is called a Global variable.

True
False

IIT Kharagpur Week 6 10


Introduction to Internet of Things
5
Question No: 36

Which of the following is used to read a text file in Python?

file = open(‘data.txt’, ‘r ’)
file = open_text(‘data.txt’, ‘r ’)
file = read_text(‘data.txt’, ‘r ’)
file = read(‘data.txt’, ‘r ’)

IIT Kharagpur Week 6 10


Introduction to Internet of Things
6
Question No: 36

Which of the following is used to read a text file in Python?

file = open(‘data.txt’, ‘r ’)
file = open_text(‘data.txt’, ‘r ’)
file = read_text(‘data.txt’, ‘r ’)
file = read(‘data.txt’, ‘r ’)

IIT Kharagpur Week 6 10


Introduction to Internet of Things
7
Question No: 37

Which of the following library in Python is used for processing images.

Pillow
Numpy
Panda
None of these

IIT Kharagpur Week 6 10


Introduction to Internet of Things
8
Question No: 37

Which of the following library in Python is used for processing images.

Pillow
Numpy
Panda
None of these

IIT Kharagpur Week 6 10


Introduction to Internet of Things
9
Question No: 38

In python, image cannot be converted to grey scale.

True
False

IIT Kharagpur Week 6 11


Introduction to Internet of Things
0
Question No: 38

In python, image cannot be converted to grey scale.

True
False

IIT Kharagpur Week 6 11


Introduction to Internet of Things
1
Question No: 39

Which of the following shortcut exits the nano editor?

Ctrl + E
Ctrl + O
Ctrl+V
None of these

IIT Kharagpur Week 6 11


Introduction to Internet of Things
2
Question No: 39

Which of the following shortcut exits the nano editor?

Ctrl + E
Ctrl + O
Ctrl+V
None of these

IIT Kharagpur Week 6 11


Introduction to Internet of Things
3
Question No: 40

Which of the following is an unordered data type in Python?

List
Dictionary
Both List and Dictionary
Tuple

IIT Kharagpur Week 6 11


Introduction to Internet of Things
4
Question No: 40

Which of the following is an unordered data type in Python?

List
Dictionary
Both List and Dictionary
Tuple

IIT Kharagpur Week 6 11


Introduction to Internet of Things
5
Question No: 41

Which of the following converts energy to motion?

Actuator
Raspberry Pi
Sensor
None of these

IIT Kharagpur Week 6 11


Introduction to Internet of Things
6
Question No: 41

Which of the following converts energy to motion?

Actuator
Raspberry Pi
Sensor
None of these

IIT Kharagpur Week 6 11


Introduction to Internet of Things
7
Question No: 42

Python does not follow strict indentation.

True
False

IIT Kharagpur Week 6 11


Introduction to Internet of Things
8
Question No: 42

Python does not follow strict indentation.

True
False

IIT Kharagpur Week 6 11


Introduction to Internet of Things
9
Question No: 43

Functions cannot be reassigned to the variables in Python.

True
False

IIT Kharagpur Week 6 12


Introduction to Internet of Things
0
Question No: 43

Functions cannot be reassigned to the variables in Python.

True
False

IIT Kharagpur Week 6 12


Introduction to Internet of Things
1
Question No: 44

You can execute Python programs within a Raspberry Pi

a. True
b. False

IIT Kharagpur Week 6 12


Introduction to Internet of Things
2
Question No: 44

You can execute Python programs within a Raspberry Pi

a. True
b. False

IIT Kharagpur Week 6 12


Introduction to Internet of Things
3
Question No: 45

Which among the following libraries in Python do you use to generate and plot graphs

a. numpy
b. time
c. matplotlib
d. random

IIT Kharagpur Week 6 12


Introduction to Internet of Things
4
Question No: 45

Which among the following libraries in Python do you use to generate and plot graphs

a. numpy
b. time
c. matplotlib
d. random

IIT Kharagpur Week 6 12


Introduction to Internet of Things
5
Question No: 46

A programmer needs to execute a python code that requires RAM support of 1GB SDRAM, Quad cortex [email protected]
CPU, 400 MHz video core IV GPU, and 802.11 wireless communication support. Select the appropriate device where
the code can be executed?

a. Raspberry Pi zero
b. Raspberry Pi 2 model B
c. Raspberry Pi 3 model B
d. Arduino Uno

IIT Kharagpur Week 6 12


Introduction to Internet of Things
6
Question No: 46

A programmer needs to execute a python code that requires RAM support of 1GB SDRAM, Quad cortex [email protected]
CPU, 400 MHz video core IV GPU, and 802.11 wireless communication support. Select the appropriate device where
the code can be executed?

a. Raspberry Pi zero
b. Raspberry Pi 2 model B
c. Raspberry Pi 3 model B
d. Arduino Uno

IIT Kharagpur Week 6 12


Introduction to Internet of Things
7
Question No: 47

Raspberry Pi 3 has ________ GB internal storage.

a. three
b. zero
c. four
d. one

IIT Kharagpur Week 6 12


Introduction to Internet of Things
8
Question No: 47

Raspberry Pi 3 has ________ GB internal storage.

a. three
b. zero
c. four
d. one

IIT Kharagpur Week 6 12


Introduction to Internet of Things
9
Question No: 48

Which among the following is a wearable Arduino board?


a. Arduino Uno
b. Arduino Mega
c. RedBoard Arduino
d. LilyPad Arduino

IIT Kharagpur Week 6 13


Introduction to Internet of Things
0
Question No: 48

Which among the following is a wearable Arduino board?


a. Arduino Uno
b. Arduino Mega
c. RedBoard Arduino
d. LilyPad Arduino

IIT Kharagpur Week 6 13


Introduction to Internet of Things
1
Question No: 49

In Python, the following is the syntax of the sleep function:


time.sleep(secs)
The argument <secs> should be __________.

•Integer
•Float
•Either integer or float
•Range

IIT Kharagpur Week 6 13


Introduction to Internet of Things
2
Question No: 49

In Python, the following is the syntax of the sleep function:


time.sleep(secs)
The argument <secs> should be __________.

•Integer
•Float
•Either integer or float
•Range

IIT Kharagpur Week 6 13


Introduction to Internet of Things
3
Question No: 50

Which of the following is the extension for your python file in Raspberry Pi?
a. .py
b. .pi
c. .rpi
d. .rpy

IIT Kharagpur Week 6 13


Introduction to Internet of Things
4
Question No: 50

Which of the following is the extension for your python file in Raspberry Pi?
a. .py
b. .pi
c. .rpi
d. .rpy

IIT Kharagpur Week 6 13


Introduction to Internet of Things
5
Question No: 51

What are variables that are declared and has its scope within a function in python called?

a. Global variable
b. Local variable
c. Hierarchical variable
d. Dangling variable

IIT Kharagpur Week 6 13


Introduction to Internet of Things
6
Question No: 51

What are variables that are declared and has its scope within a function in python called?

a. Global variable
b. Local variable
c. Hierarchical variable
d. Dangling variable

IIT Kharagpur Week 6 13


Introduction to Internet of Things
7
Question No: 52

In raspberry pi, what is the command for capturing an image?

a. raspicapture
b. raspicam
c. raspisnap
d. raspistill

IIT Kharagpur Week 6 13


Introduction to Internet of Things
8
Question No: 52

In raspberry pi, what is the command for capturing an image?

a. raspicapture
b. raspicam
c. raspisnap
d. raspistill

IIT Kharagpur Week 6 13


Introduction to Internet of Things
9
Question No: 53

Python doesn’t support strict rules for syntax.

a. True
b. False

IIT Kharagpur Week 6 14


Introduction to Internet of Things
0
Question No: 53

Python doesn’t support strict rules for syntax.

a. True
b. False

IIT Kharagpur Week 6 14


Introduction to Internet of Things
1
Question No: 54

Fill in the blanks. __________ is a data-type in Python.

a. List
b. Tuple
c. Dictionary
d. All of these

IIT Kharagpur Week 6 14


Introduction to Internet of Things
2
Question No: 54

Fill in the blanks. __________ is a data-type in Python.

a. List
b. Tuple
c. Dictionary
d. All of these

IIT Kharagpur Week 6 14


Introduction to Internet of Things
3
Question No: 55

Fill in the blanks. __________are the variables declared inside a function.

a. Immediate variables
b. Global variables
c. Local variables
d. None of these

IIT Kharagpur Week 6 14


Introduction to Internet of Things
4
Question No: 55

Fill in the blanks. __________are the variables declared inside a function.

a. Immediate variables
b. Global variables
c. Local variables
d. None of these

IIT Kharagpur Week 6 14


Introduction to Internet of Things
5
Question No: 56

What does the open() function return for file operations?

a. File mode
b. File object
c. File name
d. None of these

IIT Kharagpur Week 6 14


Introduction to Internet of Things
6
Question No: 56

What does the open() function return for file operations?

a. File mode
b. File object
c. File name
d. None of these

IIT Kharagpur Week 6 14


Introduction to Internet of Things
7
Question No: 57

Python does not follow rigid indentation.

a. True
b. False

IIT Kharagpur Week 6 14


Introduction to Internet of Things
8
Question No: 57

Python does not follow rigid indentation.

a. True
b. False

IIT Kharagpur Week 6 14


Introduction to Internet of Things
9
Question No: 58

Which of the following is used to display an image in Python?

a. image.show()
b. image.open()
c. image.name()
d. image.mode()

IIT Kharagpur Week 6 15


Introduction to Internet of Things
0
Question No: 58

Which of the following is used to display an image in Python?

a. image.show()
b. image.open()
c. image.name()
d. image.mode()

IIT Kharagpur Week 6 15


Introduction to Internet of Things
1
Question No: 59

Which of the following models does python follow for networking.

a. Client-server
b. P2P
c. All of these
d. None of these

IIT Kharagpur Week 6 15


Introduction to Internet of Things
2
Question No: 59

Which of the following models does python follow for networking.

a. Client-server
b. P2P
c. All of these
d. None of these

IIT Kharagpur Week 6 15


Introduction to Internet of Things
3
Question No: 60

In python, ”with” ensures the file is closed after the operation is completed, but not when an exception occurs.

a. True
b. False

IIT Kharagpur Week 6 15


Introduction to Internet of Things
4
Question No: 60

In python, ”with” ensures the file is closed after the operation is completed, but not when an exception occurs.

a. True
b. False

IIT Kharagpur Week 6 15


Introduction to Internet of Things
5
Question No: 61

In Raspberry Pi, GPIO acts only as a digital output.

a. True
b. False

IIT Kharagpur Week 6 15


Introduction to Internet of Things
6
Question No: 61

In Raspberry Pi, GPIO acts only as a digital output.

a. True
b. False

IIT Kharagpur Week 6 15


Introduction to Internet of Things
7
Question No: 62

Which of the following exists the nano editor in the terminal?

a. Ctrl+O
b. Ctrl+X
c. Ctrl+A
d. None of these

IIT Kharagpur Week 6 15


Introduction to Internet of Things
8
Question No: 62

Which of the following exists the nano editor in the terminal?

a. Ctrl+O
b. Ctrl+X
c. Ctrl+A
d. None of these

IIT Kharagpur Week 6 15


Introduction to Internet of Things
9
Question No: 63

Does Raspberry Pi provide configuration options for cameras ?

a. Yes
b. No

IIT Kharagpur Week 6 16


Introduction to Internet of Things
0
Question No: 63

Does Raspberry Pi provide configuration options for cameras ?

a. Yes
b. No

IIT Kharagpur Week 6 16


Introduction to Internet of Things
1
Question No: 64

Does python provide a module for pi-camera ?

a. Yes
b. No

IIT Kharagpur Week 6 16


Introduction to Internet of Things
2
Question No: 64

Does python provide a module for pi-camera ?

a. Yes
b. No

IIT Kharagpur Week 6 16


Introduction to Internet of Things
3
Question No: 65

Which of the following converts energy to motion?

a. Actuator
b. Raspberry Pi
c. All of these
d. None of these

IIT Kharagpur Week 6 16


Introduction to Internet of Things
4
Question No: 65

Which of the following converts energy to motion?

a. Actuator
b. Raspberry Pi
c. All of these
d. None of these

IIT Kharagpur Week 6 16


Introduction to Internet of Things
5
Question No: 65

Which of the following is a property of a Relay.

a. Mechanical switch
b. Electrochemical switch
c. None of these
d. All of these

IIT Kharagpur Week 6 16


Introduction to Internet of Things
6
Question No: 65

Which of the following is a property of a Relay.

a. Mechanical switch
b. Electrochemical switch
c. None of these
d. All of these

IIT Kharagpur Week 6 16


Introduction to Internet of Things
7
Question No: 66

Sensors can be neither analog nor digital.

a. True
b. False

IIT Kharagpur Week 6 16


Introduction to Internet of Things
8
Question No: 66

Sensors can be neither analog nor digital.

a. True
b. False

IIT Kharagpur Week 6 16


Introduction to Internet of Things
9
Question No: 67

State whether true or false.


It is not possible to return multiple values from a function in Python.

a. True
b. False

IIT Kharagpur Week 6 17


Introduction to Internet of Things
0
Question No: 67

State whether true or false.


It is not possible to return multiple values from a function in Python.

a. True
b. False

IIT Kharagpur Week 6 17


Introduction to Internet of Things
1
Question No: 68

Which among the following libraries in Python do you use to generate and plot graphs

a. numpy
b. time
c. matplotlib
d. random

IIT Kharagpur Week 6 17


Introduction to Internet of Things
2
Question No: 68

Which among the following libraries in Python do you use to generate and plot graphs

a. numpy
b. time
c. matplotlib
d. random

IIT Kharagpur Week 6 17


Introduction to Internet of Things
3
Question No: 69

A programmer needs to execute a python code that requires RAM support of 1GB SDRAM, Quad cortex [email protected]
CPU, 400 MHz video core IV GPU, and 802.11 wireless communication support. Select the appropriate device where
the code can be executed?

a. Raspberry Pi zero
b. Raspberry Pi 2 model B
c. Raspberry Pi 3 model B
d. Arduino Uno

IIT Kharagpur Week 6 17


Introduction to Internet of Things
4
Question No: 69

A programmer needs to execute a python code that requires RAM support of 1GB SDRAM, Quad cortex [email protected]
CPU, 400 MHz video core IV GPU, and 802.11 wireless communication support. Select the appropriate device where
the code can be executed?

a. Raspberry Pi zero
b. Raspberry Pi 2 model B
c. Raspberry Pi 3 model B
d. Arduino Uno

IIT Kharagpur Week 6 17


Introduction to Internet of Things
5
Question No: 70

Raspberry Pi 3 has ________ GB internal storage.

a. three
b. zero
c. four
d. one

IIT Kharagpur Week 6 17


Introduction to Internet of Things
6
Question No: 70

Raspberry Pi 3 has ________ GB internal storage.

a. three
b. zero
c. four
d. one

IIT Kharagpur Week 6 17


Introduction to Internet of Things
7
Question No: 71

Which among the following is a wearable Arduino board?


a. Arduino Uno
b. Arduino Mega
c. RedBoard Arduino
d. LilyPad Arduino

IIT Kharagpur Week 6 17


Introduction to Internet of Things
8
Question No: 71

Which among the following is a wearable Arduino board?


a. Arduino Uno
b. Arduino Mega
c. RedBoard Arduino
d. LilyPad Arduino

IIT Kharagpur Week 6 17


Introduction to Internet of Things
9
Question No: 72

In Python, the following is the syntax of the sleep function:


time.sleep(secs)
The argument <secs> should be __________.

•Integer
•Float
•Either integer or float
•Range

IIT Kharagpur Week 6 18


Introduction to Internet of Things
0
Question No: 72

In Python, the following is the syntax of the sleep function:


time.sleep(secs)
The argument <secs> should be __________.

•Integer
•Float
•Either integer or float
•Range

IIT Kharagpur Week 6 18


Introduction to Internet of Things
1
Question No: 73

Which of the following is the extension for your python file in Raspberry Pi?
a. .py
b. .pi
c. .rpi
d. .rpy

IIT Kharagpur Week 6 18


Introduction to Internet of Things
2
Question No: 73

Which of the following is the extension for your python file in Raspberry Pi?
a. .py
b. .pi
c. .rpi
d. .rpy

IIT Kharagpur Week 6 18


Introduction to Internet of Things
3
Question No: 74

What are variables that are declared and has its scope within a function in python called?

a. Global variable
b. Local variable
c. Hierarchical variable
d. Dangling variable

IIT Kharagpur Week 6 18


Introduction to Internet of Things
4
Question No: 74

What are variables that are declared and has its scope within a function in python called?

a. Global variable
b. Local variable
c. Hierarchical variable
d. Dangling variable

IIT Kharagpur Week 6 18


Introduction to Internet of Things
5
Question No: 75

In raspberry pi, what is the command for capturing an image?

a. raspicapture
b. raspicam
c. raspisnap
d. raspistill

IIT Kharagpur Week 6 18


Introduction to Internet of Things
6
Question No: 75

In raspberry pi, what is the command for capturing an image?

a. raspicapture
b. raspicam
c. raspisnap
d. raspistill

IIT Kharagpur Week 6 18


Introduction to Internet of Things
7
Thank You

IIT Kharagpur Week 6 18


Annual Review Presentation
8

You might also like