0% found this document useful (0 votes)
3 views8 pages

Python Lab

Python lab file for btech

Uploaded by

kumarvarun3162
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

Python Lab

Python lab file for btech

Uploaded by

kumarvarun3162
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

2323802

Practical 1
Aim: Write a program to demonstrate basic data type in python.
Theory: Data types define the kind of data that can be stored and manipulated in
programming. Common types include integers (whole numbers), floats (decimal numbers),
strings (text), Boolean (True/False), and complex types like lists, tuples, and dictionaries.
Correct data types ensure efficient storage and accurate operations.

Software Use:- Vs Code

Source Code:
a= 10
print("The data type of A will be: ", type(a))
b = 39.20
print("The data type of B will be: ", type(b))
c = 'char'
print("The data type of C will be: ", type(c))
2323802

d = []
print("The data type of D will be: ", type(d))
e = ()
print("The data type of E will be: ", type(e))
f = {}
print("The data type of F will be: ", type(f))
import numpy as np
g = np.random.randint(10,200,10).reshape(5,2)
print("The data type of G will be: ", type(g))
h = None
print("The data type of H will be: ", type(h))
Output:
2323802

Practical 2
AIM: Write a program for checking whether the given number is an even
or not.
Theory : This program checks whether a given number is even by using the
modulus operator (%). An even number is divisible by 2 with no remainder, so
if number % 2 == 0, the number is considered even. The program uses a
function a() to encapsulate this logic, and based on the result, it prints whether
the number is even or not. User input is handled by the input() function,
converted to an integer for the calculation.
Software Use:- Vs Code
Source Code:
a=int(input("Enter the number: "))
if(a%2==0):
print('The input is even')
else:
print('The input is odd')
Output:-
2323802

Practical 3
Aim: Write a program using a for loop that loops over a sequence.

Theory: A `for` loop in Python iterates over each element in a sequence (like
lists, strings). It processes each element one-by-one, executing a code block
during every iteration.

Software Use:- Vs Code

Source Code:
sequence = [10, 20, 30, 40, 50]
for item in sequence:
print(f'Item: {item}')

Output:
2323802

PRACTICAL 4
AIM: Write a program to demonstrate string, tuple dictionaries in python.
Theory:
 String: A sequence of characters. It demonstrates indexing and finding the
length of a string.
 Tuple: An immutable ordered collection. It shows accessing elements and
finding the length.
 Dictionary: A collection of key-value pairs. It demonstrates accessing values
by key, and retrieving keys and values.
Software Used: Vs code
Source Code:
# String demonstration
my_string = "Hello, Python!"
print("String:", my_string)
print("First character of the string:", my_string[0])
print("Length of the string:", len(my_string))

# Tuple demonstration
my_tuple = (1, 2, 3, 4, 5)
print("\nTuple:", my_tuple)
print("First element of the tuple:", my_tuple[0])
print("Length of the tuple:", len(my_tuple))

# Dictionary demonstration
my_dict = {
"name": "Alice",
"age": 30,
"city": "New York"
}
print("\nDictionary:", my_dict)
print("Name:", my_dict["name"])
print("Keys in the dictionary:", my_dict.keys())
print("Values in the dictionary:", my_dict.values())
2323802

Output:
2323802

Practical 5
Aim: Write a program to perform logical and mathematical operation.
Theory:
 Mathematical Operations:
 Addition (+), Subtraction (-), Multiplication (*), Division (/), Modulus
(%), and Exponentiation (**) are performed on the values of a and b.
 Logical Operations:
 Logical AND (x and y), OR (x or y), and NOT (not x) are demonstrated
using the boolean variables x and y.
Source Code:
# Mathematical operations
a = 10
b=5

# Addition
add = a + b
print("Addition:", add)

# Subtraction
subtract = a - b
print("Subtraction:", subtract)

# Multiplication
multiply = a * b
print("Multiplication:", multiply)

# Division
divide = a / b
print("Division:", divide)

# Modulus
modulus = a % b
print("Modulus:", modulus)

# Exponentiation
power = a ** b
2323802

print("Exponentiation:", power)

# Logical operations
x = True
y = False
# Logical AND
print("\nLogical AND:", x and y)

# Logical OR
print("Logical OR:", x or y)

# Logical NOT
print("Logical NOT x:", not x)
print("Logical NOT y:", not y)

Output:

You might also like