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

PRACTICAL FILE Fds

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

PRACTICAL FILE Fds

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

PRACTICAL FILE

SESSION: 2024-25

Fundamentals Of Data Science Lab


( AIML 203)
II Year, I Sem

Submitted to: Submitted by:


Name: Mr. Ramandeep Saha Name: Nimesh Chauhan
Designation: Assistant Professor Enrollment No. 00318011623
EXPERIMENT 2

Design a Python program to generate and print a list except for the first 5 elements,
where the values are squares of numbers between 1 and 30.

Source Code:

squares = [x**2 for x in range (1, 31)]


square = squares [5:]
print(square)

Output:
EXPERIMENT 3

Design a Python program to understand the working of loops.

Source Code:
# Example of a for loop
print("For Loop Example: Squares of numbers from 1 to 5")
for i in range(1, 6):
print(f"The square of {i} is {i**2}")

# Example of a while loop


print("\nWhile Loop Example: Counting down from 5 to 1")
count = 5
while count > 0:
print(f"Countdown: {count}")
count -= 1

# Example of a nested loop (Multiplication table)


print("\nNested Loop Example: Multiplication table (1 to 3)")
for i in range(1, 4):
for j in range(1, 4):
print(f"{i} * {j} = {i * j}")
print("----")

# Example of a loop with break and continue


print("\nLoop with Break and Continue:")
for i in range(1, 10):
if i == 5:
print(f"Skipping {i} (using continue)")
continue # Skip the number 5
if i == 8:
print(f"Stopping loop at {i} (using break)")
break # Stop the loop when i is 8
print(i)

# Example of an infinite loop (with break to stop it)


print("\nInfinite While Loop (Demonstrating break)")
count = 0
while True:
print(f"Infinite loop count: {count}")
count += 1
if count == 3:
print("Stopping the infinite loop with break")
break # Break the infinite loop

Output:
EXPERIMENT 4

Design a Python function to find the Max of three numbers.

Source Code:

def find_max_of_three(a, b, c):


numbers = [a, b, c]
max_num = numbers[0]
for num in numbers:
if num > max_num:
max_num = num
return max_num

num1 = 5
num2 = 10
num3 = 8

print(f"The maximum of {num1}, {num2}, and {num3} is:


{find_max_of_three(num1, num2, num3)}")
Output:
EXPERIMENT 5

Design a Python program for creating a random story generator

Source Code:

import random

# Lists of different components of the story


characters = ['a wizard', 'a dragon', 'an astronaut', 'a knight', 'a scientist', 'a pirate', 'a
robot']
settings = ['in a magical forest', 'on a distant planet', 'in a haunted castle', 'under the
sea', 'in a futuristic city']
actions = ['found a mysterious object', 'fought a terrible enemy', 'discovered a
hidden treasure', 'saved the world', 'met a talking animal']
objects = ['a magic wand', 'a glowing sword', 'a golden key', 'an ancient book', 'a
strange device']

# Function to generate a random story


def generate_story():
character = random.choice(characters)
setting = random.choice(settings)
action = random.choice(actions)
obj = random.choice(objects)
# Combine the randomly selected parts into a story
story = f"Once upon a time, {character} was {setting}. They suddenly {action}
with {obj}!"

return story

# Generate and print a random story


random_story = generate_story()
print(random_story)

Output:
EXPERIMENT 6
Create a synthetic dataset (.csv/.xlsx) to work upon and design a python
program to read and print that data.

Source Code:

import csv

# Step 1: Create synthetic dataset


data = [
["ID", "Name", "Age", "Occupation", "Salary"],
[1, "Alice", 28, "Data Scientist", 85000],
[2, "Bob", 35, "Software Engineer", 95000],
[3, "Charlie", 22, "Designer", 55000],
[4, "Diana", 40, "Product Manager", 115000],
[5, "Ethan", 30, "DevOps Engineer", 90000]
]

# Step 2: Write the dataset to a CSV file


csv_filename = "synthetic_dataset.csv"
with open(csv_filename, mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerows(data)

print(f"Synthetic dataset written to {csv_filename}")

# Step 3: Read the dataset from the CSV file and print its content
with open(csv_filename, mode='r') as file:
reader = csv.reader(file)
for row in reader:
print(row)

Output:

You might also like