Name: Rehan Satti
Roll No: 24836
Class: BS CS 3rd Semester
Subject: AI
Python Lab:
1. Program to display messages (with comments)
# This program displays welcome messages
print("Welcome to Python")
print("Welcome to Engineering")
print("Programming is fun")
Output
Welcome to Python
Welcome to Engineering
Programming is fun
2. Program to display the result of: 2 + 15 * 2 / 2
result = 2 + 15 * 2 / 2
print(result)
Output
17.0
3. Program to display the result of an expression
result = (10 + 5) * 2
print("Result:", result)
Output
Result: 30
4. Add parentheses to change value from 4 to -6
Original expression:
6*1-2=4
Modified expression:
# Changing value using parentheses
result = 6 * (1 - 2)
print(result)
Output
-6
5. Area and Perimeter of a Rectangle
width = 4.9
height = 7.5
area = width * height
perimeter = 2 * (width + height)
print("Area:", area)
print("Perimeter:", perimeter)
Output
Area: 36.75
Perimeter: 24.8
6. Celsius to Fahrenheit Converter:
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (9 / 5) * celsius + 32
print("Temperature in Fahrenheit:", fahrenheit)
Output
Enter temperature in Celsius: 25
Temperature in Fahrenheit: 77.0
7. Miles to Kilometers Converter
miles = float(input("Enter distance in miles: "))
kilometers = miles * 1.609
print("Distance in kilometers:", kilometers)
Output
Enter distance in miles: 5
Distance in kilometers: 8.045
8. Surface Area and Volume of a Cylinder
import math
radius = float(input("Enter radius: "))
height = float(input("Enter height: "))
surface_area = 2 * [Link] * radius * radius + 2 * [Link] * radius *
height
volume = [Link] * radius * radius * height
print("Surface Area of Cylinder:", surface_area)
print("Volume of Cylinder:", volume)
Output
Enter radius: 3
Enter height: 5
Surface Area of Cylinder: 150.79644737231007
Volume of Cylinder: 141.3716694115407