LabManual(BDS306B)
LabManual(BDS306B)
1.Develop a python program to read n digit integer number, and separate the integer
number and display each digit. [Hint: input:5678 output: 5 6 7 8, use: floor and mod
operators)
Output:
2.Develop a python program to accept 4 numbers and display them in sorted order using a
minimum number of if else statements.
# Accept 4 numbers
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
num3 = int(input("Enter the third number: "))
num4 = int(input("Enter the fourth number: "))
CSE(DataScience) Page 1
Lab ManualPython Programming for DataScience(BDS306B)
Output:
3.Develop a python script to rotate right about a given position in that list and display them.
#[hint: input [1,4,5,-10] position: 2, output: [-10,5,4,1]]
# Create a List
myList =[1,4,5,-10]
CSE(DataScience) Page 2
Lab ManualPython Programming for DataScience(BDS306B)
Output:
4.Develop python scripts to Calculate the mean, median, mode, variance and standard
deviation of n integer numbers.
# Calculate Mean
mean = sum(numbers) / n
# Calculate Median
numbers.sort()
if n % 2 == 0:
median = (numbers[n // 2 - 1] + numbers[n // 2]) / 2
else:
median = numbers[n // 2]
# Calculate Mode
frequency = {num: numbers.count(num) for num in numbers}
max_count = max(frequency.values())
mode = [k for k, v in frequency.items() if v == max_count]
CSE(DataScience) Page 3
Lab ManualPython Programming for DataScience(BDS306B)
# Display results
print(f"Mean: {mean}")
print(f"Median: {median}")
print(f"Mode: {mode}")
print(f"Sample Variance: {variance_sample}")
print(f"Population Variance: {variance_population}")
print(f"Sample Standard Deviation: {std_deviation_sample}")
print(f"Population Standard Deviation: {std_deviation_population}")
Output:
n=int(input("Enter number:"))
temp=n
rev=0
while(n>0):
digit=n%10 # Get the last digit
rev=rev*10+digit # Build the reversed number
n=n//10 # Remove the last digit from the number
if(temp==rev):
print("The number is a palindrome!")
else:
print("The number isn't a palindrome!")
Output:
CSE(DataScience) Page 4
Lab ManualPython Programming for DataScience(BDS306B)
number = int(input ("Enter the number of which the user wants to print the
multiplication table: "))
# We are using "for loop" to iterate the multiplication 10 times
print ("The Multiplication Table of: ", number)
for count in range(1, 11):
print (number, 'x', count, '=', number * count)
Output:
7. Develop write a python script to interchange the digits of a given integer number.
[hint: input: 23456, interchange: 3 and 5 output: 25436]
Output:
CSE(DataScience) Page 5
Lab ManualPython Programming for DataScience(BDS306B)
8. Develop a python program to capitalize a given list of strings. [hint: [hello, good, how, simple]
output: [Hello, Good, How, Simple]
def capitalize_strings(string_list):
# Capitalize each string in the list
return [s.capitalize() for s in string_list]
'''The capitalize() function in Python is used to capitalize the first letter of a string. '''
# Example usage
input_strings = ['hello', 'good', 'how', 'simple']
capitalized_strings = capitalize_strings(input_strings)
print(capitalized_strings)
Output:
9.Using a dictionary, develop a python program to determine and print the number of duplicate
words in a sentence.
def count_duplicate_words(sentence):
# Split the sentence into words
words = sentence.split()
if duplicates:
print("Duplicate words and their counts:")
CSE(DataScience) Page 6
Lab ManualPython Programming for DataScience(BDS306B)
# Example usage
sentence = input("Enter a sentence: ")
count_duplicate_words(sentence)
Output:
10.Develop python program to read Numpy array and print row (sum,mean std) and
column(sum,mean,std)
import numpy as np
CSE(DataScience) Page 7
Lab ManualPython Programming for DataScience(BDS306B)
print(meanr)
print("Column Mean")
print(meanc)
print("__________________________________________")
stdr = data.std(axis=1)
stdc = data.std(axis=0)
print("Row STD")
print(stdr)
print("Column STD")
print(stdc)
Output:
11.Develop a python program to read and print in the #console CSV file.
CSV file:
file name: employee_birthday.csv
CSE(DataScience) Page 8
Lab ManualPython Programming for DataScience(BDS306B)
Program11.py
import csv
with open('employee_birthday.csv') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
for row in csv_reader:
if line_count == 0:
print(f'Column names are {", ".join(row)}')
line_count += 1
else:
print(f'\t{row[0]} works in the {row[1]} department, and was born in {row[2]}.')
line_count += 1
print(f'Processed {line_count} lines.')
Output:
12.Develop a python program to read a HTML file with basic#tags, and construct a dictionary
and display the same in the console.
CSE(DataScience) Page 9
Lab ManualPython Programming for DataScience(BDS306B)
<th>Department</th>
</tr>
<tr>
<td>Alice</td>
<td>30</td>
<td>HR</td>
</tr>
<tr>
<td>Bob</td>
<td>25</td>
<td>IT</td>
</tr>
<tr>
<td>Charlie</td>
<td>35</td>
<td>Finance</td>
</tr>
</table>
</body>
</html>
"""
#-----------------------------------------------------------------------
#output:HTML file 'table.html' has been created.
#---------------------------------------------------------------------------
import pandas as pd
def read_html_to_dict(html_file):
# Read all tables from the HTML file
tables = pd.read_html(html_file)
CSE(DataScience) Page 10
Lab ManualPython Programming for DataScience(BDS306B)
return tables_dict
if __name__ == '__main__':
html_file = 'table.html' # Replace with your HTML file path
result = read_html_to_dict(html_file)
Output:
{'Table_1': {'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [30, 25, 35], 'Department': ['HR', 'IT',
'Finance']}}
CSE(DataScience) Page 11