def average():
test1=float(input("Enter marks for test1 "))
test2=float(input("Enter marks for test2 "))
test3=float(input("Enter marks for test3 "))
marks=[test1, test2, test3]
[Link](reverse=True)
best_avg=(marks[0] + marks[1])/ 2
print(f"the average of 2 tests {best_avg: .2f}")
average()
def palindrome():
num=input("Enter a number ")
if num==num[::-1]:
print(f"the {num} is palindrome")
else:
print(f"the {num} is not palindrome")
print("Digit Occurances")
for digit in set(num):
print(f"{digit}: {[Link](digit)}")
palindrome()
def fibonacci(n):
if n <= 0:
print("Error the number should be greater tahn 0")
return
fib=[0, 1]
for i in range(2,n):
[Link](fib[-1]+fib[-2])
print(f"the fibonacci sequence is {n} sequence {fib[:n]}")
try:
N=int(input("Enter a positive integer "))
fibonacci(N)
except ValueError:
print("invalid input")
2b)
def binary_to_decimal(binary):
return int(binary,2)
def ocatl_to_hexadecimal(octal):
decimal=int(octal,8)
return hex(decimal)[2:]
binary=input("Enter a binary number")
print(f" Decimal number is: {binary_to_decimal(binary)}")
octal=input("Enter a octal number")
print(f" Hexadecimal number is :{ocatl_to_hexadecimal(octal)} ")
3a)
def analyze_sentence():
sentence=input("Enter a sentence")
words=[Link]()
digits=sum([Link]() for c in sentence)
uppercase=sum([Link]() for c in sentence)
lowercase=sum([Link]() for c in sentence)
print(f" Number of words: {len(words)} ")
print(f" Number of digits: {digits} ")
print(f" Number of uppercase: {uppercase} ")
print(f"Number of lowercase: {lowercase} ")
analyze_sentence()
3b)
from difflib import SequenceMatcher
def string_similarity(s1,s2):
similarity=SequenceMatcher(None,s1,s2).ratio()
print(f" The similarity between two strings '{s1}' and '{s2}' :{similarity: .2f} ")
str1=input("Enter the first string ")
str2=input("Enter the second string ")
string_similarity(str1, str2)
4a)
import [Link] as plt
hours = [5,5.5,6,6.5,7,7.5,8,8.5,9,9.5,10, 10.5,11, 11.5,12,12.5,13,13.5,14]
marks = [60,62,65,66, 68, 70, 71,68,66,65,64,62,60,58,45,43,42,40,35]
[Link] (hours, marks)
[Link]("Hours to Marks Correlation")
[Link]("Hours")
[Link]("Marks")
[Link]()
4b)
import [Link] as plt
hours = [5,5.5,6,6.5,7,7.5,8,8.5,9,9.5,10, 10.5,11, 11.5,12,12.5,13,13.5,14]
marks = [60,62,65,66, 68, 70, 71,68,66,65,64,62,60,58,45,43,42,40,35]
[Link] (hours, marks)
[Link]("Hours to Marks Correlation")
[Link]("Hours")
[Link]("Marks")
[Link]()
5a)
import [Link] as plt
from [Link] import load_iris
iris = load_iris()
sepal_lengths = [Link][:, 0]
[Link](sepal_lengths, bins=15, color='green', edgecolor='black', alpha=0.8)
[Link]('Distribution of Sepal Lengths (Iris Dataset)')
[Link]('Sepal Length (cm)')
[Link]('Frequency')
[Link]()
5b)
import [Link] as plt
import numpy as np
y = [Link]([35, 25, 25, 15])
mylabels = ["Apples", "Bananas", "Cherries", "Dates"]
myexplode = [0.2, 0, 0, 0]
[Link](y, labels = mylabels, explode = myexplode, shadow = True, autopct='%.2f')
[Link]()