Lab Manual Python-2
Lab Manual Python-2
/subject
code /Version no.
LAB MANUAL<TEACHER’S/STUDENT’S>
LAB IN CHARGE:
ASIET VISION
To emerge as a Center of Excellence in Engineering, Technology and Management by
imparting quality education, focusing on empowerment and innovation.
ASIET MISSION
Impart quality professional education for total upliftment of the society.
Create congenial academic ambience that kindles innovative thinking and research.
Mould competent professionals who are socially committed and responsible citizens.
COURSE SYLLABUS
COURSE OUTCOMES
CO Course Knowledge
No. Outcome Level
CO1
CO2
CO3
CO4
BEST PRACTICES
INDEX
EXP NO:1
OBJECTIVE:
LEARNING OUTCOMES:
THEORY:
The print() function in Python is one of the most frequently used functions,
and its purpose is to output data to the standard output device, typically the
console or terminal.
The input() function in Python is used to accept user input from the standard
input device, typically the keyboard.
ALGORITHM/FLOW CHART:
CODE:
print("Value of z:", z)
print(x,y,z)
(5) Print with Formatted String (f-strings)
name = "Alice"
age = 25
city = "New York"
print(f"My name is {name}. I am {age} years old and I live in {city}.")
(6) Print with Separator and End Parameter
print("Apple", "Banana", "Cherry", sep=", ")
print("Learning Python", end=" ")
print("is fun!")
(7) Use Concatenation in Print
first_name = "John"
last_name = "Doe"
age = 30
full_name = first_name + " " + last_name
print("Full Name: " + full_name)
print("Welcome, " + first_name + "! Today is a great day.")
(8) Prompts the user for a name and print a greeting
name = input("Enter your name: ")
print("Hello, " + name + "!")
(9) Taking multiple inputs
value1, value2, value3 = input("Enter three values ").split()
print(f"Value 1: {value1}")
print(f"Value 2: {value2}")
print(f"Value 3: {value3}")
PROCEDURE:
EXPECTED OUTPUT:
INFERENCE:
EXP NO:2
OBJECTIVE:
LEARNING OUTCOMES:
SOFTWARE REQUIRED:
THEORY:
1. Start.
2. Input the complex number z.
3. Extract the real part of z using the attribute z.real.
4. Extract the imaginary part of z using the attribute z.imag.
5. Display the real part (z.real).
6. Display the imaginary part (z.imag).
7. End.
CODE:
principal = 1000.0
rate = 5.5
time = 2.5
simple_interest = (principal * rate * time) / 100
print(f"Principal Amount: {principal}")
print(f"Rate of Interest: {rate}%")
print(f"Time (in years): {time}")
print(f"Simple Interest: {simple_interest:.2f}")
(4) Create complex numbers and do basic operations such as
addition, subtraction, multiplication, and division.
z1 = complex(2, 3)
z2 = complex(1, 4)
add_result = z1 + z2
print(f"Addition: {z1} + {z2} = {add_result}")
sub_result = z1 - z2
print(f"Subtraction: {z1} - {z2} = {sub_result}")
mul_result = z1 * z2
print(f"Multiplication: {z1} * {z2} = {mul_result}")
div_result = z1 / z2
print(f"Division: {z1} / {z2} = {div_result}")
(5) Access real and imaginary parts of a complex number
z = complex(3, 5) # 3 + 5j
real_part = z.real
imaginary_part = z.imag
print(f"Complex Number: {z}")
print(f"Real Part: {real_part}")
print(f"Imaginary Part: {imaginary_part}")
(6) Compare two numbers and print the Boolean values True/False
num1 = 10
num2 = 5
is_greater = num1 > num2
is_equal = num1 == num2
is_less_equal = num1 <= num2
print(f"Is {num1} greater than {num2}? {is_greater}")
print(f"Is {num1} equal to {num2}? {is_equal}")
print(f"Is {num1} less than or equal to {num2}? {is_less_equal}")
(7) Create a string, list, tuple, set, dictionary and print them
my_tuple = tuple(my_list)
print(f"List {my_list} converted to tuple: {my_tuple}")
# Tuple to List
my_tuple = (4, 5, 6)
my_list = list(my_tuple)
print(f"Tuple {my_tuple} converted to list: {my_list}")
# List to Set
my_list = [1, 2, 2, 3, 4]
my_set = set(my_list)
print(f"List {my_list} converted to set (duplicates removed):
{my_set}")
# Set to List
my_set = {7, 8, 9}
my_list = list(my_set)
print(f"Set {my_set} converted to list: {my_list}")
# Boolean to Integer
bool_val = True
int_val = int(bool_val)
print(f"Boolean {bool_val} converted to integer: {int_val}")
# Integer to Boolean
num = 0
bool_val = bool(num)
print(f"Integer {num} converted to boolean: {bool_val}")
num = 42
bool_val = bool(num)
print(f"Integer {num} converted to boolean: {bool_val}")
# String to Boolean
str_val = ""
bool_val = bool(str_val)
print(f"String '{str_val}' converted to boolean: {bool_val}")
str_val = "Hello"
bool_val = bool(str_val)
print(f"String '{str_val}' converted to boolean: {bool_val}")
PROCEDURE:
The programs which demonstrate the fundamental data types are successfully
executed and the results are obtained.
EXP NO:3
OBJECTIVE:
LEARNING OUTCOMES:
python.
● To apply fundamental python constructs in solving the basic
mathematical problems.
SOFTWARE REQUIRED:
THEORY:
ALGORITHM/FLOW CHART:
CODE:
(2) Calculate the area and perimeter of a rectangle given its length
and breadth
length = float(input("Enter the length of the rectangle: "))
breadth = float(input("Enter the breadth of the rectangle: "))
area = length * breadth
perimeter = 2 * (length + breadth)
print("Area:",area )
print("Perimeter:",perimeter)
(3) Find the hypotenuse of a right triangle using Pythagoras
theorem.
import math
b=int(input("Enter the base"))
a=int(input("Enter the altitude"))
temp=a**2+b**2
h=math.sqrt(temp)
print("The hypotenuse is",h)
(4) To input two values a and b and then swap them
a=int(input("Enter a number"))
b=int(input("Enter another number"))
print("The numbers before swapping are a =",a,"and b =",b)
temp=a
a=b
b=temp
print("The numbers after swapping are a =",a,"and b =",b)
PROCEDURE:
EXPECTED OUTPUT:
2. What is the difference between / and // in Python, and when would you
use each?
INFERENCE:
ANNEXURES
PROGRAM OUTCOMES (POs)
the engineering and management principles and apply these to one’s own work, as a
member and leader in a team, to manage projects and in multidisciplinary
environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological
change.