(Done) Lab 03 Python Lab Journal 26092024 114551am
(Done) Lab 03 Python Lab Journal 26092024 114551am
CSL-325
Lab Journal 03
Fall 2023
AI-Lab journal - #
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
Output:
Task 2:
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
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')
df.fillna(df.mean(numeric_only=True), inplace=True)
Output: