Iot Lab Manual
Iot Lab Manual
2. Select the latest stable release of Python for your operating system. (e.g., Windows, Mac OS X, or Linux)
4. Open the downloaded file and follow the instructions to install Python.
5. During the installation process, you will be asked to choose an installation directory and whether you want to
add Python to your system path. It is generally a good idea to add Python to your system path, which allows you
to use Python from any directory in the command line.
6. Once the installation is complete, open your command prompt or terminal and type "python" to confirm that
Python is installed correctly.
7. If the Python installation was successful, you will see the Python version number and the Python prompt (>>>)
appear on the screen.
You can also verify the installation by running a simple Python command such as "print('Hello, World!')" in the Python
prompt
EXPERIMENT-2
OBJECTIVE:- Prepare a python program using print() function and run it.
python code
Example 1:
import array
my_array = array.array('i', [1, 2, 3, 4, 5])
my_array[0] = 10
print(my_array) output: array('i', [10, 2, 3, 4, 5])
Example 2:
import array
x=array.array('u',['p','b','c','d'])
x[2]='m'
print(x) output: array('u', 'pbmd'
EXPERIMENT-3
OBJECTIVE:- Access given value from the tuple
Tuple Variables: Tuple variables are similar to list variables, but they are immutable, meaning that their values
cannot be changed once they are created.
You can declare a tuple variable by enclosing the values in parentheses, like this:
python code
EXAMPLE 1:
OUTPUT:-
Car
EXAMPLE 2:
tup1 = ('car' , 'bus' ,444);
print ( "tup1[0]: ",tup1[0]);
OUTPUT:-
tup1[0]: car
EXPERIMENT-4
Dictionary Variables: Dictionary variables are used to store key-value pairs. They are often used to store and access
data in a structured way.
We can declare a dictionary variable by enclosing the key-value pairs in curly braces, like this:
python code
output:
Madhubani
OUTPUT:-
GAUTAM BUDDHA
EXPERIMENT-5
OBJECTIVE:-Write a Python program to create an array of 5 integers and display the array items. Access individual element
through indexes
Creating an array
To create an array in Python, you first need to import the array module. Then, you can use the array() function to
create an array. Next, you can create an array by specifying the type of data it will contain and initializing it with
some values. Here's an example of how to create an array of integers:
Python code
import array
a = array.array('f', [5, 6, 7, 9, 0, 9, 00])
print(a)
In this example, f is the type code for float. You can use different type codes to create arrays of other data types.
python code
import array
my_array = array.array('i', [1, 2, 3, 4, 5])
print(my_array[0])
OUTPUT:- 1
EXPERIMENT-6
OBJECTIVE:-Write a Python program which takes two digits m (row) and n (column) as input and generates a two- dimensional
array.
2D ARRAY: A 2D array in python is a two-dimensional data structure stored linearly in the memory. It means that it has two
dimensions, the rows, and the columns, and thus it also represents a matrix.
array_name=[n_rows][n_columns]
Where array_name is the array's name, n_rows is the number of rows in the array, and n_columns is the number of columns in the array.
python code
OUTPUT:
ENTER THE NO OF ROWS : 3
ENTER THE NO OF COLUMNS : 4
1 2 3 4
2 4 6 8
3 6 9 12
EXPERIMENT-7
OBJECTIVE:- Write a python program to check whether person is eligible for voting or not. (accept age from
the user)
python code
AGE=int(input("Enter your age : "))
if AGE>= 18:
print("You are eligible for voting")
else :
print("you are not eligible for voting")
OUTPUT:-
Enter your age : 17
you are not eligible for voting
python code
OUTPUT:-
Enter a number: 20
The entered number is EVEN
Enter a number: 21
The entered number is ODD
EXPERIMENT-9
OBJECTIVE:Write a python program to check whether entered number is divisible by another entered number.
python code
OUTPUT:
Enter first number: 200
Enter second number: 5
First number is divisible by second number
Write a python program to display “Yes” is entered number is divisible by 5 otherwise display “No”
Output:
Enter a number: 50
YES
Enter a number: 77
NO
x = int(input("Enter a number: "))
i = 1
while i <= x:
if i % 2 == 0:
print(i, end=" ")
i = i + 1
print(2 * i - 1)
Q3:- Write a python program which can print first 10 integers and its square using while/for loop.
i=1
print(i, i * i)
i += 1
print(i, i * i)
OTHER
# Using for loop
square = i * i
i=1
square = i * i
i += 1
Q4:
i=1
sum = 0
sum += i
i += 1
print(sum)
sum += i
print(sum)
EXPLANATION:
This program first initializes a variable i to 1. Then, it uses a while loop to iterate from 1 to 10, and
adds each number to a variable sum. The loop terminates when i is greater than or equal to 10.
The program then uses a for loop to iterate from 1 to 10, and adds each number to a variable sum.
The loop terminates when i is equal to 11.
To run the program, you can save it as a Python file and then run it from the command line. For
example, if you save the program as sum_of_first_10_natural_numbers.py, you can run it by typing
the following command into the command line:
python sum_of_first_10_natural_numbers.py
This will print the sum of the first 10 natural numbers to the console.
55
55
Q5: Write a python program which can identify the prime number between the range given using while/for loop.
if num < 2:
continue
is_prime = True
if num % i == 0:
is_prime = False
break
if is_prime:
print(num)
OUTPUT:
Enter the start of the range: 7
Enter the end of the range: 101
Prime numbers in the given range:
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
101
print()
Q7: Consider the situation when you need to write a program which prints the number from 1 to 10 and but not 6. It is specified
that you have to do this using loop and only one
loop is allowed to use.
if i == 6:
continue
else:
print(i)
OUTPUT:
1
2
3
4
5
7
8
9
10
pass
person1 = Person()
person1.name = "Alice"
person1.age = 30
person2 = Person()
person2.name = "Bob"
person2.age = 25
print("Name:", person1.name)
print("Age:", person1.age)
print("City:", person1.city)
print("------------------------")
print("Name:", person2.name)
print("Age:", person2.age)
print("City:", person2.city)
class Vehicle:
pass
In this class, we don't define any instance variables (attributes) or methods. It is just an empty class
definition.
This class can be used as a blueprint for creating instances of vehicles. You can later add attributes
and methods to this class as per your specific requirements. For example, you can add instance
variables like color, make, model, year, etc., and methods like start_engine(), stop_engine(), accelerate(),
brake(), etc., to make it more meaningful and functional as a representation of a vehicle.
# Find the maximum of the three numbers using nested conditional statements
max_number = num1
max_number = num2
max_number = num3
OUTPUT:
Enter the first number: 45
Enter the second number: 89
Enter the third number: 9999
The maximum of the three numbers is: 9999
reversed_str = ""
The program then prints the reversed string as the output. For example, if you enter "hello", the
output will be: