0% found this document useful (0 votes)
10 views

(Done) Lab 03 Python Lab Journal 26092024 114551am

Uploaded by

Gamer S.H.G
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)
10 views

(Done) Lab 03 Python Lab Journal 26092024 114551am

Uploaded by

Gamer S.H.G
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/ 6

Artificial Intelligence

CSL-325

Lab Journal 03

Fall 2023

Department of Computer Science, Bahria University, Islamabad,


Campus
Name: Syed Zeeshan Azhar
Enrollment: 01-134221-080

AI-Lab journal - #

Lab Journal 2-B:

1. Create list of Fibonacci numbers after calculating Fibonacci series up to the number n
which you will pass to a function as an argument. The number n must be input by the user.
They are calculated using the following formula: The first two numbers of the series is
always equal to 1, and each consecutive number returned is the sum of the last two
numbers. Hint: Can you use only two variables in the generator function?
a=1
b=2
a, b = b, a
will simultaneously switch the values of a and b.
The first number in the series should be 1. (The output will start like 1,1,2,3,5,8,...)

Code:
def Fibonacci_series (target):
Fibonacci = [1]
n = 0
counter = 0
while n <= target:
Fibonacci.append(n)
n = n + Fibonacci[counter]
counter = counter + 1
Fibonacci.Pop(0)
Fibonacci.Pop(0)
return Fibonacci

target = float(input("Enter the target Number: "))


Fibonacci = Fibonacci_series(target)
print(Fibonacci)

Output:
Task 2:

VOWELS = ['a', 'e', 'i', 'o', 'u']

def convert_to_pig_latin(word):
if word[0].lower() in VOWELS:
return word + "hay"
else:
return word[1:] + word[0] + "ay"
sentence = input("Enter a sentence in English: ")
words = sentence.split()
counter = 0
pig_latin_words = []
while counter < len(words):
word = words[counter]
pig_latin_word = convert_to_pig_latin(word)
pig_latin_words.append(pig_latin_word)
counter += 1
pig_latin_sentence = " ".join(pig_latin_words)
print(pig_latin_sentence)

Task 3:

import pandas as pd
import numpy as np

series1 = pd.Series([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])


series2 = pd.Series([11, 8, 7, 5, 6, 5, 3, 4, 7, 1])

distance = np.sqrt(np.sum((series1 - series2) ** 2))

print(f"Euclidean Distance: {distance}")

output:
Task 4:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.read_csv('onlineretail.csv', encoding='ISO-8859-1')

print("Displaying first few rows of the dataset:")


print(df.head())

print("\nSummary of numerical fields:")


print(df.describe())

print("\nDisplaying the first and last columns:")


print(df.iloc[:, [0, -1]])

print("\nColumns with Null/NaN values:")


print(df.isnull().sum())

df.fillna(df.mean(numeric_only=True), inplace=True)

df['Revenue'] = df['Quantity'] * df['UnitPrice']


country_sales = df.groupby('Country')['Revenue'].sum().sort_values(ascending=False)

print("\nCountries contributing the most to sales revenue:")


print(country_sales)

df.hist(bins=50, figsize=(10, 8))


plt.suptitle("Histogram of Numerical Fields")
plt.show()

Output:

You might also like