0% found this document useful (0 votes)
2 views11 pages

Python

Uploaded by

ABHINAV CHAUHAN
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views11 pages

Python

Uploaded by

ABHINAV CHAUHAN
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DELHI TECHNICAL CAMPUS

Greater Noida
Affiliated to GGSIPU and Approved by AICTE & COA

PRACTICAL FILE

SESSION: 202 -2
Programming in Python Lab
CIE-332P

[Link] CS I I Year, VIth Sem

Submitted to: Submitted by:


Name: Ms. Gunjan Sethi Name: HIMANSHU CHAUHAN
Designation: Assistant Professor Enrollment No.: 1

Department of Computer Science and Engineering


Delhi Technical Campus, Greater Noida
DELHI TECHNICAL CAMPUS
Greater Noida
Affiliated to GGSIPU and Approved by AICTE & COA

INDEX
DATE OF DATE OF
NAME OF EXPERIMENT SIGNATURE
EXPERIMENT SUBMISSION
1. Create a program that prompts the user for their
name, age with a welcome message and tells them if
they can vote in the next election.

Create a program that calculates the factorial of a


number entered by the user using a loop.
2. Create a program that prompts the user for a string
and then prints out the string reversed.

Create a program that defines a function to calculate


the area of a circle based on the radius entered by the
user
3. Create a program that prompts the user for a list of
numbers and then sorts them in ascending order.
4. WAP that defines a class to represent a car and then
create an object of that class with specific attributes.
5. Create a program that reads data from a file and
writes it to another file in a different format. Create a
program that prompts the user for two numbers and
the divide them, handling any exceptions that may
rise.
6. Create a program that uses a graphical user interface
(GUI) to allow the user to perform simple
calculations.
7. Create a program that uses regular expressions to find
all instances of a specific pattern in a text file.
8. You are given a dataset
([Link]
sales-dataset) containing monthly sales data of
different product categories for a company.
Write a Python program that:
1. Reads data from this CSV file.
2. Displays basic information about the dataset.
3. Generates appropriate visualizations to analyze
sales trends.
9. Write a Python program using web scraping
techniques to fetch and save all available information
(such as hotel name, location, price, ratings,
amenities, and images) from the following Agoda
hotel webpage into a local file (CSV or text):
[Link]
delhi/hotel/[Link]
DELHI TECHNICAL CAMPUS
Greater Noida
Affiliated to GGSIPU and Approved by AICTE & COA

10. Create a program that reads a file provided by the


user and displays its contents. Handle scenarios
where the file does not exist or cannot be opened
using exception handling.
DELHI TECHNICAL CAMPUS
Greater Noida
Affiliated to GGSIPU and Approved by AICTE & COA

EXPERIMENT-1A
AIM: Basic data types and operators: Create a program that prompts the user
for their name and age and prints a personalized message.

CODE:
name = input("Enter your name: ")
age = int(input("Enter your age: "))

print(f"Welcome, {name}!")

if age >= 18:


print("You are eligible to vote in the next election.")
else:
print("You are not eligible to vote in the next election.")

OUTPUT:
DELHI TECHNICAL CAMPUS
Greater Noida
Affiliated to GGSIPU and Approved by AICTE & COA

EXPERIMENT-1B
AIM: Create a program that calculates the factorial of a number entered by the
user using a loop.

CODE:
num = int(input("Enter a number: "))
factorial = 1

for i in range(1, num + 1):


factorial *= i

print(f"Factorial of {num} is {factorial}")

OUTPUT:
DELHI TECHNICAL CAMPUS
Greater Noida
Affiliated to GGSIPU and Approved by AICTE & COA

EXPERIMENT-2A
AIM: Create a program that prompts the user for a string and then prints out
the string reversed.

CODE:
text = input("Enter a string: ")
reversed_text = text[::-1]
print(f"Reversed string: {reversed_text}")

OUTPUT:
DELHI TECHNICAL CAMPUS
Greater Noida
Affiliated to GGSIPU and Approved by AICTE & COA

EXPERIMENT-2B
AIM: Create a program that defines a function to calculate the area of a circle
based on the radius entered by the user.

CODE:
import math

def area_of_circle(radius):
return [Link] * radius ** 2

r = float(input("Enter the radius of the circle: "))


area = area_of_circle(r)
print(f"Area of the circle: {area:.2f}")

OUTPUT:
DELHI TECHNICAL CAMPUS
Greater Noida
Affiliated to GGSIPU and Approved by AICTE & COA

EXPERIMENT-3
AIM: Create a program that prompts the user for a list of numbers and then
sorts them in ascending order.

CODE:
numbers = input("Enter numbers separated by spaces: ").split()
numbers = [float(n) for n in numbers]
[Link]()
print(f"Sorted list: {numbers}")

OUTPUT:
DELHI TECHNICAL CAMPUS
Greater Noida
Affiliated to GGSIPU and Approved by AICTE & COA

EXPERIMENT-4
AIM: WAP that defines a class to represent a car and then create an object of
that class with specific attributes.

CODE:
class Car:
def __init__(self, brand, model, year, color):
[Link] = brand
[Link] = model
[Link] = year
[Link] = color

def display(self):
print(f"Brand: {[Link]}")
print(f"Model: {[Link]}")
print(f"Year: {[Link]}")
print(f"Color: {[Link]}")

car1 = Car("Toyota", "Camry", 2023, "White")


print("Car Details:")
[Link]()

OUTPUT:
DELHI TECHNICAL CAMPUS
Greater Noida
Affiliated to GGSIPU and Approved by AICTE & COA

EXPERIMENT-5A
AIM: Create a program that reads data from a file and writes it to another file in
a different format.

CODE:
with open("[Link]", "r") as infile:
lines = [Link]()

with open("[Link]", "w") as outfile:


[Link]("Field,Value\n")
for line in lines:
if ":" in line:
key, value = [Link]().split(":", 1)
[Link](f"{[Link]()},{[Link]()}\n")

print("Data read from [Link]:")


with open("[Link]", "r") as f:
print([Link]())

print("Data written to [Link]:")


with open("[Link]", "r") as f:
print([Link]())

OUTPUT:

[Link]
DELHI TECHNICAL CAMPUS
Greater Noida
Affiliated to GGSIPU and Approved by AICTE & COA

EXPERIMENT-5B
AIM: Create a program that prompts the user for two numbers and the divide
them, handling any exceptions that may rise.

CODE:
try:
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
result = num1 / num2
print(f"Result: {num1} / {num2} = {result}")
except ZeroDivisionError:
print("Error: Cannot divide by zero!")
except ValueError:
print("Error: Please enter valid numbers!")
except Exception as e:
print(f"An unexpected error occurred: {e}")

OUTPUT:

You might also like