0% found this document useful (0 votes)
7 views3 pages

Module4 Applied Python Smart Genset Notes

Module 4 covers essential Python concepts including data types, keywords, identifiers, conditional statements, iterative statements, functions, and library importing using PIP. It provides examples for each topic, demonstrating how to use Python for smart generator applications. Key functionalities such as decision-making, loops, and code reuse through functions are emphasized.
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)
7 views3 pages

Module4 Applied Python Smart Genset Notes

Module 4 covers essential Python concepts including data types, keywords, identifiers, conditional statements, iterative statements, functions, and library importing using PIP. It provides examples for each topic, demonstrating how to use Python for smart generator applications. Key functionalities such as decision-making, loops, and code reuse through functions are emphasized.
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

Module 4: Applied Python for Smart Genset - Notes

Topics: Data Types, Keywords, Identifiers, Conditional Statements, Iterative Statements, Functions,
Library Importing using PIP

1. Data Types in Python


Data types define the type of data that a variable can store. Python automatically detects the data
type based on the assigned value.
Data Type Example Description
Integer x = 10 Stores whole numbers
Float temperature = 36.5 Stores decimal numbers
String name = 'Generator' Stores text values
Boolean status = True Represents True or False
List sensor = [10,20,30] Stores multiple values in one variable

Example:
temperature = 35.5
fuel_level = 60
generator_name = "Smart Genset"

2. Python Keywords
Keywords are reserved words in Python that have special meaning and cannot be used as variable
names.
Examples of Python keywords:
if
else
while
for
def
return
import
True
False

3. Identifiers
Identifiers are names used for variables, functions, and classes in Python.
Rules for identifiers:
• Must start with a letter or underscore
• Cannot start with a number
• Cannot be a Python keyword
• Should be meaningful names
Examples:
fuel_level
temperature_sensor
engine_status

4. Conditional Statements
Conditional statements are used to perform decision-making operations in programs.
Example: if statement
fuel_level = 15

if fuel_level < 20:


print("Low Fuel Warning")
Example: if-else
temperature = 80

if temperature > 90:


print("Overheat")
else:
print("Normal Temperature")
Example: if-elif-else
temp = 85

if temp > 100:


print("Danger")
elif temp > 80:
print("Warning")
else:
print("Normal")

5. Iterative Statements (Loops)


Loops are used to execute a block of code multiple times.
Example: for loop
for i in range(5):
print("Sensor Reading")
Example: while loop
fuel = 10

while fuel < 20:


print("Low Fuel")
fuel += 1

6. Functions
Functions are reusable blocks of code that perform a specific task.
Example Function:

def check_fuel(level):
if level < 20:
print("Low Fuel")
else:
print("Fuel OK")

check_fuel(15)

7. Library Importing using PIP


PIP is a package manager used to install external Python libraries.
Install a library:
pip install requests

Check installed libraries:


pip list
Using a library in Python:

import math
print([Link](16))

Example: Smart Genset Temperature Monitoring


temperature = 95

if temperature > 90:


print("Generator Overheat Warning")
else:
print("Temperature Normal")

You might also like