[go: up one dir, main page]

0% found this document useful (0 votes)
12 views9 pages

Iot Ca4

The document provides examples of using Python dictionaries to store customer data for a churn prediction model, including storing customer IDs as keys and customer details as values. It also provides examples of Python programming concepts like string concatenation, case conversion, loops, functions, and GPIO control on Raspberry Pi.

Uploaded by

Tiyasha Neogi
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)
12 views9 pages

Iot Ca4

The document provides examples of using Python dictionaries to store customer data for a churn prediction model, including storing customer IDs as keys and customer details as values. It also provides examples of Python programming concepts like string concatenation, case conversion, loops, functions, and GPIO control on Raspberry Pi.

Uploaded by

Tiyasha Neogi
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/ 9

1) What is the difference between procedure-oriented programming and object-

oriented programming?

4
[Module 3/CO3/Understand-LOCQ]

2) What is an interpreted Language? 3 [Module 3/CO3/Analyze-IOCQ]


An interpreted language is a language in which the implementations execute
instructions directly without earlier compiling a program into machine language.
3) Describe a use of case of Python Dictionary.
5
[Module 3/CO3/Understand-IOCQ]

Suppose you are a data scientist working on a project to classify customer churn. You have
a dataset of customer data, including their demographics, purchase history, and support
tickets. You want to build a model to predict which customers are most likely to churn.
One way to do this would be to use a Python dictionary to store the customer data. The keys
of the dictionary would be the customer IDs, and the values would be the customer data.
You could then use the dictionary to look up the data for each customer and use that data to
train your model.

customers = {
"12345": {
"name": "John Doe",
"age": 30,
"purchase_history": [
{"item": "iPhone", "price": 1000},
{"item": "iPad", "price": 500},
],
"support_tickets": [
{"issue": "Problem with iPhone", "status": "resolved"},
{"issue": "Problem with iPad", "status": "open"},
],
},
"67890": {
"name": "Jane Doe",
"age": 25,
"purchase_history": [
{"item": "MacBook", "price": 2000},
{"item": "AirPods", "price": 150},
],
"support_tickets": [
{"issue": "Problem with MacBook", "status": "resolved"},
],
},
}

4) What is a Keyword argument in Python? 4


[Module 3/CO3/Analyze-IOCQ]
Keyword arguments (or named arguments) are values that, when passed into a
function, are identifiable by specific parameter names.
5) What are variable length arguments? 4
[Module 3/CO3/Understand-IOCQ]
Variable length arguments, often referred to as Varases, allow a function to accept
any number of arguments.
6) What is the difference between a Python module and a package? 5
[Module 3/CO3/Understand-IOCQ]

7) How is function overriding implemented in Python? 5


[Module 3/CO3/Understand-IOCQ]
Function overriding in Python is achieved through inheritance and polymorphism.
When a subclass defines a method with the same name as a method in its
superclass, it overrides the behavior of that method.
Inheritance: The subclass inherits methods from its superclass.
Method Redefinition: The subclass redefines (overrides) a method from its
superclass with the same name.
Polymorphism: When an overridden method is called on an object of the subclass,
the method defined in the subclass is executed instead of the method in the
superclass.
class Animal:
def make_sound(self):
print("Animal makes a sound")
class Dog(Animal):
def make_sound(self):
print("Dog barks")

# Create instances
animal = Animal()
dog = Dog()

# Call the overridden method


animal.make_sound() # Output: "Animal makes a sound"
dog.make_sound() # Output: "Dog barks"
8) Write a Python programming for string concatenation. 5
[Module 3/CO3/Apply-HOCQ]
# Define two strings
string1 = "Hello, "
string2 = "world!"

# Concatenate the strings


concatenated_string = string1 + string2

# Print the concatenated string


print(concatenated_string)
9) Write a Python programming to transfer an upper-case string to lower case. 5
[Module 3/CO3/Apply-HOCQ]
# Define an uppercase string
uppercase_string = "HELLO, WORLD!"

# Convert the uppercase string to lowercase


lowercase_string = uppercase_string.lower()

# Print the lowercase string


print(lowercase_string)
10) Write a Python programming to execute for / while statement. 5
[Module 3/CO3/Apply-HOCQ]
# Example of a for loop
print("Executing for loop:")
for i in range(5): # Loop from 0 to 4
print("Iteration", i)

# Example of a while loop


print("\nExecuting while loop:")
counter = 0
while counter < 5:
print ("Iteration", counter)
counter += 1
11) Write a Python programming to provide function for date and time conversion. 5
[Module 3/CO3/Apply-HOCQ]
from datetime import datetime

def convert_datetime(input_datetime, input_format, output_format):


# Convert input datetime string to a datetime object
datetime_obj = datetime.strptime(input_datetime, input_format)

# Convert datetime object to the desired output format


output_datetime = datetime_obj.strftime(output_format)

return output_datetime

# Example usage
input_datetime = "2024-05-04 12:30:45"
input_format = "%Y-%m-%d %H:%M:%S"
output_format = "%A, %B %d, %Y - %I:%M %p"

converted_datetime = convert_datetime(input_datetime, input_format,


output_format)
print("Converted datetime:", converted_datetime)
12) Describe the interfaces of Raspberry Pi. 5
[Module 4/CO4/Analyze-IOCQ]
The Raspberry Pi has a variety of interfaces that allow it to communicate with the
outside world using protocols like HDMI, USB, and Ethernet:
HDMI: High-Definition Multimedia Interface port for displaying video output from the
computer.
RCA: Port for other display options
USB: Four USB ports
Ethernet: One Ethernet connection
Micro SD slot: For storage
3.5mm audio/video port: Combined port for audio and video
Bluetooth: Bluetooth connection
Serial Peripheral Interface (SPI): Allows for up to two attached devices.
Inter-Integrated-Circuit bus (I2C): Allows for many devices if their addresses don't
conflict.
Serial port: Provides low speed +3.3V TTL RS-232 data communication with
devices like sensors, displays, ADCs, and DACs
13) How Raspberry pi is different from a desktop computer? 2
[Module 4/CO4/Understand-LOCQ]
Raspberry Pi is smaller, cheaper, and designed for educational/hobbyist projects,
while desktop computers are larger, more expensive, and versatile for various tasks
including gaming and multimedia editing.
14) What is the use of GPIO pins? 2
[Module 4/CO4/Understand-IOCQ]
A GPIO (general-purpose input/output) port handles both incoming and outgoing digital
signals. As an input port, it can be used to communicate to the CPU the ON/OFF signals
received from switches, or the digital readings received from sensors.
15) What is the use of SPI and 12C interfaces on Raspberry Pi? 5
[Module 4/CO4/Analyze-IOCQ]
The Serial Peripheral Interface (SPI) and Inter-Integrated Circuit (I2C) are
communication protocols that enable the Raspberry Pi to communicate with a
variety of external devices. Both are bidirectional, synchronous, serial
communication interfaces used for short distances.
16) Explain the function of Raspberry Pi commands (any five) 5
[Module 4/CO4/Analyze-IOCQ]
df /: Shows how much free disk space is available
dpkg - -get-selections | grep XXX: Shows all installed packages related to XXX
dpkg - -get-selections: Shows all installed packages
free: Shows how much free memory is available
hostname -I: Shows the Raspberry Pi's IP address
lsusb: Lists USB hardware connected to the Raspberry Pi
vcgencmd measure_temp: Shows the CPU's temperature
mv: Moves or renames a file
rm: Deletes a file or directory
cp: Copies a file
mkdir: Creates a new directory
apt: Installs and manages software
sudo apt update: Updates the list of installable software
sudo apt install vlc: Installs a specific application
sudo apt upgrade -y: Upgrades all software on the Raspberry Pi
17) Write a Python program for switching LED ON/OFF from Raspberry Pi console.
import RPi.GPIO as GPIO
import time

# Set the GPIO pin mode to BCM


GPIO.setmode(GPIO.BCM)

# Set GPIO pin 18 as output


GPIO.setup(18, GPIO.OUT)

# Turn on the LED


GPIO.output(18, GPIO.HIGH)

# Wait for 1 second


time.sleep(1)

# Turn off the LED


GPIO.output(18, GPIO.LOW)

# Clean up the GPIO pins


GPIO.cleanup()
18) Write a Python program for blinking LED. 5
[Module 4/CO4/Apply-HOCQ]
import RPi.GPIO as GPIO
import time

# Set the GPIO pin number for the LED


LED_PIN = 17

# Set the GPIO mode to BCM


GPIO.setmode(GPIO.BCM)

# Set the LED pin as output


GPIO.setup(LED_PIN, GPIO.OUT)

# Blink the LED


while True:
GPIO.output(LED_PIN, GPIO.HIGH)
time.sleep(1)
GPIO.output(LED_PIN, GPIO.LOW)
time.sleep(1)
19) Write a Python program for controlling LED with a switch. 5
[Module 4/CO4/Apply-HOCQ]
import RPi.GPIO as GPIO
import time

# Set up GPIO
LED_PIN = 18
SWITCH_PIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED_PIN, GPIO.OUT)
GPIO.setup(SWITCH_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)

try:
while True:
# Read switch state
switch_state = GPIO.input(SWITCH_PIN)
# If switch is pressed (LOW), turn LED on
if switch_state == GPIO.LOW:
print("Switch pressed - LED ON")
GPIO.output(LED_PIN, GPIO.HIGH)
else:
print("Switch released - LED OFF")
GPIO.output(LED_PIN, GPIO.LOW)

time.sleep(0.1) # Add a small delay to debounce the switch

except KeyboardInterrupt:
# Clean up GPIO
GPIO.cleanup()
20) Describe the basic building block of an IoT Device. 5
[Module 4/CO4/Analyze-IOCQ]
The basic building blocks of an IoT device include a microcontroller/microprocessor,
sensors, communication modules, actuators, power supply, memory/storage, and
application software.

21) Explain the main characteristics of Python. 5


[Module 4/CO4/Analyze-IOCQ]
Easy to learn and use:
Python has a simple syntax that is easy to read and write, making it a good choice
for beginners.
Interpreted language:
Python is an interpreted language, which means that it does not need to be
compiled before it can be run. This makes it easier to develop and debug Python
code.
Object-oriented:
Python supports object-oriented programming, which allows developers to create
reusable and modular code.
Portable:
Python code can be run on a variety of platforms, including Windows, Mac, and
Linux.
Free and open source:
Python is free and open-source software, which means that it is freely available to
use and distribute.
Large standard library:
Python comes with a large standard library that includes modules for a variety of
tasks, such as file I/O, networking, and web development.
22) Describe any one control flow statement in Python and give an Example.
5
[Module 4/CO4/Apply-HOCQ]
One control flow statement in Python is the "if" statement, used for conditional
execution of code blocks.
x = 10
if x > 5:
print ("x is greater than 5")
23) Describe break/continue statement in Python with an example.
5
[Module 4/CO4/Apply-HOCQ]
The "break" statement is used to exit a loop prematurely, while the "continue" statement is
used to skip the rest of the current iteration and proceed to the next iteration of the loop.
# Example of break statement
for i in range(5):
if i == 3:
break
print(i)
# Output: 0 1 2

# Example of continue statement


for i in range(5):
if i == 2:
continue
print(i)
# Output: 0 1 3 4
24) Define Django architecture.
5
[Module 5/CO4/Analyze-IOCQ]
Django is a free and open-source web application framework written in Python. It
follows the Model-View-Template (MVT) architectural pattern.

25) Explain the process of installation of Django REST framework.


5
[Module 5/CO4/Analyze-IOCQ]
Open your terminal or command prompt.
Use pip, the Python package manager, to install Django REST Framework:
Copy code
pip install djangorestframework
Once the installation is complete, you can start using DRF in your Django projects
by adding it to your installed apps in the Django settings file and configuring your
project's URLs to include DRF's routers and views.
26) What are the functions of URL pattern in Django?
5
[Module 5/CO4/Analyze-HOCQ]
URL patterns in Django route incoming requests to the appropriate view functions
based on the URL, enabling parameter passing and namespacing for organized
web application development.
URL patterns in Django facilitate the routing of incoming requests to the appropriate
view functions, enabling developers to build organized and maintainable web
applications.
27) Describe the database setting to use MySQL with a Django project.
5
[Module 5/CO4/Apply-HOCQ]

You might also like