Python Practical Unit 1
Python Practical Unit 1
MANESH PATEL
PRESIDENT INSTITUTE OF COMPUTER APPLICAION COLLEGE, SHAYONA CAMPUS, A’BAD.
a=5
b = 10
a=a+b
b=a-b
a=a-b
num1 = complex (input ("Enter the first complex number (e.g., 2+3j) = "))
num2 = complex (input ("Enter the second complex number (e.g., 4+5j)= "))
PREPARED BY: PATEL MANESH - M.Sc(CA & IT) Contact: 90165 17796 1
PATEL MANESH
import array
for i in byte_array:
print(i, end=" ")
print()
byte_array[1] = 200
s
PREPARED BY: PATEL MANESH - M.Sc(CA & IT), B.ED Contact: 90165 17796 2
PATEL MANESH
Output:
Original array=
10 20 30 40 50
Modified array=
10 200 30 40 50
Output:
s
PREPARED BY: PATEL MANESH - M.Sc(CA & IT), B.ED Contact: 90165 17796 3
PATEL MANESH
list1 = [1, 2, 3, 4, 5]
list2 = [4, 5, 6, 7, 8]
common_elements = []
non_common_elements = []
s
PREPARED BY: PATEL MANESH - M.Sc(CA & IT), B.ED Contact: 90165 17796 4
PATEL MANESH
a = 10
b = 10
if a is b:
print("a and b are same object ")
else:
print("a and b are not same object ")
x = [1, 2, 3]
y = [1, 2, 3]
s
PREPARED BY: PATEL MANESH - M.Sc(CA & IT), B.ED Contact: 90165 17796 5
PATEL MANESH
result = eval(expression)
s
PREPARED BY: PATEL MANESH - M.Sc(CA & IT), B.ED Contact: 90165 17796 6
PATEL MANESH
import math
while True:
print("\n----- MENU -----")
print("1. Find area of Circle")
print("2. Find area of Triangle")
print("3. Find area of Square and Rectangle")
print("4. Find Simple Interest")
print("5. Exit")
if choice == 1:
radius = float(input("Enter radius of the circle: "))
area = math.pi * radius ** 2
print(f"Area of Circle = {area:.2f}")
elif choice == 2:
base = float(input("Enter base of the triangle: "))
height = float(input("Enter height of the triangle: "))
area = 0.5 * base * height
print(f"Area of Triangle = {area:.2f}")
elif choice == 3:
print("1. Square")
print("2. Rectangle")
shape_choice = int(input("Choose shape (1 for Square, 2 for Rectangle): "))
s
PREPARED BY: PATEL MANESH - M.Sc(CA & IT), B.ED Contact: 90165 17796 7
PATEL MANESH
if shape_choice == 1:
side = float(input("Enter side of the square: "))
area = side ** 2
print(f"Area of Square = {area:.2f}")
elif shape_choice == 2:
length = float(input("Enter length of the rectangle: "))
breadth = float(input("Enter breadth of the rectangle: "))
area = length * breadth
print(f"Area of Rectangle = {area:.2f}")
else:
print("Invalid option for shape!")
elif choice == 4:
principal = float(input("Enter Principal amount: "))
rate = float(input("Enter Rate of interest: "))
time = float(input("Enter Time in years: "))
si = (principal * rate * time) / 100
print(f"Simple Interest = {si:.2f}")
elif choice == 5:
print("Exiting the program. Goodbye!")
break
else:
print("Invalid choice! Please enter a number between 1 and 5.")
s
PREPARED BY: PATEL MANESH - M.Sc(CA & IT), B.ED Contact: 90165 17796 8
PATEL MANESH
try:
num = float(input("Enter a number greater than zero: "))
assert num > 0, "Number must be greater than zero!"
print(f"You entered a valid number: {num}")
except AssertionError as e:
print("AssertionError:", e)
except ValueError:
print("Invalid input! Please enter a numeric value.")
s
PREPARED BY: PATEL MANESH - M.Sc(CA & IT), B.ED Contact: 90165 17796 9
PATEL MANESH
s
PREPARED BY: PATEL MANESH - M.Sc(CA & IT), B.ED Contact: 90165 17796 10
PATEL MANESH
s
PREPARED BY: PATEL MANESH - M.Sc(CA & IT), B.ED Contact: 90165 17796 11