PythonLabSemester2_merged (2) (2)
PythonLabSemester2_merged (2) (2)
SCIENCE, GWALIOR
(Deemed University)
(Declared Under Distinct Category by Ministry of
Education, Government of India)
NAAC Accredited with A++ Grade
A
Practical File
On
Python Programming Lab
(20241207)
SUBMITTED BY
SATYAM MISHRA
BTET24O1119
ET B (Batch B1)
Semester II
Electronics and Telecommunication Engineering
SUBMITTED TO
Dr. Himanshu Singh
CODE:
integer_var = 10
float_var = 10.5
string_var = "Hello, World!"
boolean_var = True
list_var = [1, 2, 3, 4, 5]
tuple_var = (1, 2, 3, 4, 5)
dictionary_var = {"name": "Alice", "age": 25}
set_var = {1, 2, 3, 4, 5}
none_var = None
OUTPUT:
PROGRAM 2: Write python programming to declare sequential data
types and display its data type.
CODE:
# 1. Managing Student Records (List and Tuple)
students = [("Alice", 20, "A"), ("Bob", 22, "B"), ("Charlie", 21, "A")]
print("Student Records:")
for student in students:
name, age, grade = student
print("Name: {name}, Age: {age}, Grade: {grade}")
OUTPUT:
CODE:
# 1. Addition Cases
print("Int + Int:", 5 + 10)
print("Float + Float:", 5.5 + 2.3)
print("Complex + Complex:", (2+3j) + (1+4j))
print("Int + Float:", 5 + 2.5)
print("Int + Complex:", 5 + (3+2j))
print("Float + Complex:", 2.5 + (1+3j))
# 2. Subtraction Cases
print("Int - Int:", 10 - 5)
print("Float - Float:", 5.5 - 2.3)
print("Complex - Complex:", (2+3j) - (1+4j))
print("Int - Float:", 5 - 2.5)
print("Int - Complex:", 5 - (3+2j))
print("Float - Complex:", 2.5 - (1+3j))
OUTPUT:
# 3. Subtraction is not supported for Strings, Lists, Tuples, and Sets
try:
print("String - String:", "Hello" - "World")
except TypeError as e:
print("Error:", e)
try:
print("List - List:", [1, 2, 3] - [4, 5, 6])
except TypeError as e:
print("Error:", e)
try:
print("Tuple - Tuple:", (1, 2) - (3, 4))
except TypeError as e:
print("Error:", e)
try:
print("Set - Set:", {1, 2, 3} - {2, 3})
except TypeError as e:
print("Error:", e)
OUTPUT:
PROGRAM 4: Write python programming to perform multiplication
and division and display the result.
CODE:
# 1. Integer Multiplication & Division
a = 20
b=7
try:
result = str_val / num_times # This will raise a TypeError
print(f'{str_val} / {num_times} = {result}')
except TypeError:
print("Error: Division is not supported for string data type.")
OUTPUT:
PROGRAM 5: Write a python programming to perform Boolean
operation and display the result.
CODE:
# 1. Boolean Operations in Python
bool1 = True
bool2 = False
CODE:
# 1. Logical Operations with Boolean Values
bool1 = True
bool2 = False