Python File
Python File
Python File
LABORATORY
URN: 2104355
LUDHIANA
PROGRAM-1
OUTPUT:
1
PROGRAM-2
numbers.
multi = num1*num2
div = num1/num2
expo= num1**num2
2
print("the multiplication of numbers=", multi)
OUTPUT:
multi = num1*num2
3
#divide num1 by num2
div = num1/num2
expo= num1**num2
OUTPUT:
4
PROGRAM-3
Write a program to display first character, last character, all characters except first
character, all characters except last character, all characters except the first and last
def string_operations(s):
if not s:
print("The string is
empty.") return
# First character
first_char = s[0]
# Last character
last_char = s[-1]
except_first = s[1:]
except_last = s[:-1]
except_first_last = s[1:-1]
5
reverse_s = s[::-1]
# Example usage
string_operations(input_string)
OUTPUT:
6
PROGRAM-4
principle = 0
rate = 0
time = 0
if principle <=0:
if rate <=0:
if time <=0:
7
print(f"balance after {time} years : ${total:.2f}")
OUTPUT:
8
PROGRAM-5
#Assignment Operations
x=3
y=2
x += y
print(x)
x=4
y=5
x -= y
print(x)
x=3
y=3
x *= y
print(x)
x=3
y=2
x /= y
print(x)
9
x=3
y=2
x **= y
print(x)
x=3
y=2
x %= y
print(x)
OUTPUT:
#Bitwise Operators
a = 10
b=4
print("a | b =", a | b)
10
print("~a =", ~a)
print("a ^ b =", a ^ b)
a=5
b = -10
OUTPUT:
11
PROGRAM-6
Write a program using operators to check whether the character you entered is a
consonant or not.
if char in ('a','e','i','o','u','A','E','I','O','U'):
else:
OUTPUT:
12
PROGRAM-7
Write a program to print the table of any given number using loops.
start = 1
end = 10
product = num * i
print(f"{num}*{i} = {product}")
OUTPUT:
13
Using While loop
i=1
end = 10
product = num * i
print(f"{num}*{i} = {product}")
i += 1
OUTPUT:
14
PROGRAM-8
num_row = 5
for j in range(i):
print("*", end="")
print()
OUTPUT:
15
PROGRAM-9
7890"},
3210"},
5555"}]
def print_customer_info(name):
if customer["name"] == name:
print("Customer Information:")
print("Name:", customer["name"])
print("Age:", customer["age"])
print("Email:", customer["email"])
print("Phone:", customer["phone"])
return customer
else:
16
print("customer not found")
print_customer_info(customer_name)
OUTPUT:
17
PROGRAM-10
Write a program to create dictionary with key as a string and perform basic string
functions.
my_dict = {}
my_dict["name"] = "John"
my_dict["age"] = "30"
my_dict["city"] = "Michigan"
print("Original Dictionary")
print(my_dict)
my_dict["name"] = my_dict["name"].upper()
if "city"in my_dict:
name_length = len(my_dict["name"])
18
# Display the updated dictionary
print("updated dictionary")
print(my_dict)
OUTPUT:
19
PROGRAM 11
def get_students_details():
print("Name:", name)
print("Age:", age)
def main():