<jupyter_start><jupyter_text>Advanced Digital Analysis of Algorithms Lab----- Assignments--------------- --------------- <NAME>   191001303002   MCS-1  1. Print “Hello World!”<jupyter_code>print ("Hello World")<jupyter_output>Hello World<jupyter_text>2. Add two numbers<jupyter_code>a=float(input())
b=float(input())
print(a+b)<jupyter_output>33
36
69.0<jupyter_text>3. Calculate simple interest when user inputs time, rate and year<jupyter_code>print("Enter p, r , t:")
p=float(input())
r=float(input())
t=float(input())
i=float((p*r*t)/100)
print("SI = ", i)
print("Amount = ", (p+i))<jupyter_output>Enter p, r , t:
1000
10
2
SI =  200.0
Amount =  1200.0<jupyter_text>4. Calculate compound interest when user inputs time, rate (annually) and year<jupyter_code>print("Enter p, r, t:")
p=float(input())
r=float(input())
t=float(input())
a=p*((1+(r/100))**t)
print("CI = ", (a-p))
print("Amount = ", a)<jupyter_output>Enter p, r, t:
1000
10
2
CI =  210.00000000000023
Amount =  1210.0000000000002<jupyter_text>5. Calculate area of a circle, taking diameter as input<jupyter_code>print("Enter diameter:")
d=float(input())
r=d/2
print("Area =", 3.14*r*r)<jupyter_output>Enter diameter:
20
Area = 314.0<jupyter_text>6. Take three sides of triangle and check whether triangle can be formed or not<jupyter_code>print("Enter 3 sides of triangle:")
a=float(input())
b=float(input())
c=float(input())
if a>(b+c) or b>(a+c) or c>(a+b):
    print("Triangle not possible")
else:
    print("Triangle possible")<jupyter_output>Enter 3 sides of triangle:
10
8
17
Triangle possible<jupyter_text>Using function<jupyter_code>def is_possible(a, b, c):    
    if (a + b)>c or (a + c)>b or (b + c)>a: 
        return True
    else: 
        return False        

a=float(input())
b=float(input())
c=float(input())
if is_possible(a, b, c): 
    print("Triangle possible")  
else: 
    print("Triangle not possible")<jupyter_output>10
8
17
Triangle possible<jupyter_text>7. Find the roots of ax.x + bx + c = 0<jupyter_code>from math import sqrt

print("Enter values of a, b and c: ")
a = float(input())
b = float(input())
c = float(input())

r = b**2 - (4*a*c)

if r > 0:
    x1 = (((-b) + sqrt(r))/(2*a))     
    x2 = (((-b) - sqrt(r))/(2*a))
    print("The roots are ", x1, " and ", x2)
elif r == 0:
    x = (-b) / 2*a
    print("The roots are ", x, " and ", x)
else:
    print("No roots, since the discriminant<0")<jupyter_output>Enter values of a, b and c: 
1
-1
-30
The roots are  6.0  and  -5.0<jupyter_text>8.1. Consider three points (x1, y1); (x2, y2) and (x3, y3). Calculate the area of this triangle.<jupyter_code>import math

def dist(x_1, y_1, x_2, y_2):
    l=math.sqrt((x_1-x_2)**2 + (y_1-y_2)**2)
    return l

x1=float(input("x1 : "))
y1=float(input("y1 : "))
x2=float(input("x2 : "))
y2=float(input("y2 : "))
x3=float(input("x3 : "))
y3=float(input("y3 : "))

side1=dist(x1, y1, x2, y2)
side2=dist(x1, y1, x3, y3)
side3=dist(x2, y2, x3, y3)
semi_perimeter = (side1+side2+side3)/2
a=math.sqrt(semi_perimeter*(semi_perimeter - side1)*(semi_perimeter - side2)*(semi_perimeter - side3))
print("Area = ", a)<jupyter_output>x1 : 10
y1 : 10
x2 : 24
y2 : 20
x3 : 30
y3 : 33
Area =  60.99999999999991<jupyter_text>8.2. Check whether it is a right-angled triangle or not.<jupyter_code>def dist(x_1, y_1, x_2, y_2):
    l=math.sqrt((x_1-x_2)**2 + (y_1-y_2)**2)
    return l

x1=float(input("x1 : "))
y1=float(input("y1 : "))
x2=float(input("x2 : "))
y2=float(input("y2 : "))
x3=float(input("x3 : "))
y3=float(input("y3 : "))

side1=dist(x1, y1, x2, y2)
side2=dist(x1, y1, x3, y3)
side3=dist(x2, y2, x3, y3)

print(side1, " ", side2, " ", side3)

if side1>side2 and side1>side3 and (side1**2==side2**2+side3**2):
        print("Right-angled traingle")
elif side2>side1 and side2>side3 and (side2**2==side1**2+side3**2):
        print("Right-angled traingle")
elif side3>side1 and side3>side2 and (side3**2==side1**2+side2**2):
        print("Right-angled traingle")
else:
    print("Not right-angled triangle")<jupyter_output>x1 : 10
y1 : 10
x2 : 24
y2 : 20
x3 : 30
y3 : 33
17.204650534085253   30.479501308256342   14.317821063276353
Not right-angled triangle<jupyter_text>9. Take marks of 5 subjects. Calculate percentage -Percentage > 90, Grade ‘O’ Percentage >= 80 and < 90, Grade 'E'Percentage >= 70 and < 80, Grade 'A'Percentage >= 60 and < 70, Grade 'B'Percentage >= 50 and < 60, Grade 'C'Percentage >= 40 and < 50, Grade 'D'Percentage < 40, ‘Failed’<jupyter_code>a=float(input("subject 1 score = "))
b=float(input("subject 2 score = "))
c=float(input("subject 3 score = "))
d=float(input("subject 4 score = "))
e=float(input("subject 5 score = "))

p=(a+b+c+d+e)/5
if p>90:
    print("O")
elif p>=80 and p<90:
    print("E")
elif p>=70 and p<80:
    print("A")
elif p>=60 and p<70:
    print("B")
elif p>=50 and p<60:
    print("C")
elif p>=40 and p<50:
    print("D")
elif p<40:
    print("Failed")<jupyter_output>subject 1 score = 42
subject 2 score = 37
subject 3 score = 36
subject 4 score = 43
subject 5 score = 40
Failed<jupyter_text>10. Take a number from user and check if it is an even number<jupyter_code>n=float(input())
if n%2==0:
    print("Even")
else:
    print("Odd")<jupyter_output>40
Even<jupyter_text>11. Print all number between 1 and 20<jupyter_code>for i in range(1,21):
    print(i, end=" ")<jupyter_output>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20<jupyter_text>12. Print odd numbers between 1 to 20<jupyter_code>for i in range(1,21,2):
    print(i, end=" ")<jupyter_output>1 3 5 7 9 11 13 15 17 19<jupyter_text>13. Check if the number is prime or not<jupyter_code>n=int(input("Number = "))
c=0
for i in range(1, n+1):
    if n%i==0:
        c=c+1
if c==2:
    print("Prime Number")
else:
    print("Composite Number")<jupyter_output>Number = 2
Prime Number<jupyter_text>14. Find the factorial of a number<jupyter_code>n=int(input("Number = "))
f=1
for i in range(1, n+1):
    f=f*i
print(f)<jupyter_output>Number = 5
120<jupyter_text>15. Print first 10 fibonacci number<jupyter_code>a,b=0,1
print(a)
print(b)
for i in range(1,9):
    c=a+b
    print(c)
    a=b
    b=c<jupyter_output>0
1
1
2
3
5
8
13
21
34<jupyter_text>16. Check whether the number is armstrong number or not (Eg: 153)<jupyter_code>n=int(input("Number = "))
s=0
t=n

while t>0:
    r=t%10
    s+=r**3
    t=t//10

if n==s:
    print("Armstrong number")
else:
    print("Not an Armstrong number")<jupyter_output>Number = 153
Armstrong number<jupyter_text>17. Print the all prime number between the given range<jupyter_code>l=int(input("Lower bound = "))
u=int(input("Upper bound = "))

for i in range(l,u+1):
    c=0
    for j in range(1, i+1):
        if i%j==0:
            c=c+1
    if c==2:
        print(i, end=" ")<jupyter_output>Lower bound = 5
Upper bound = 35
5 7 11 13 17 19 23 29 31<jupyter_text>18. Check whether the number is fibonacci number or not<jupyter_code>#A number is Fibonacci if and only if one or both of (5*n2 + 4) or (5*n2 – 4) is a perfect square

n=int(input("Number = "))
a=5*n*n+4
b=5*n*n-4
sra=a**0.5
srb=b**0.5
if sra**2==a or srb**2==b:
    print("Fibonacci")
else:
    print("Not a Fibonacci number")<jupyter_output>Number = 34
Fibonacci<jupyter_text>19.1. Print:1  22  333  4444  55555<jupyter_code>n=int(input("Range = "))
for i in range(1, n+1):
    for j in range(1, i+1):
        print(i, end=" ")
    print()<jupyter_output>Range = 5
1 
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5<jupyter_text>19.2. Print:    1   2 3   4 5 6    7 8 9 10<jupyter_code>n=int(input("Range = "))
k=1
for i in range(1, n+1):
    for j in range(1, i+1):
        print(k, end=" ")
        k=k+1
    print()<jupyter_output>Range = 5
1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15<jupyter_text>19.3. Print:          *            * *        * * *      * * * *<jupyter_code>#Rough work - dry run
#n=4
for i in range(1, 6):
    for j in range(6-i, 1, -1):
        print(" ", end=" ")
    for k in range(1, i):
        print("*", end=" ")
    print()
n=int(input("Range = "))
for i in range(1, n+2):
    for j in range(n+2-i, 1, -1):
        print(" ", end=" ")
    for k in range(1, i):
        print("*", end=" ")
    print()<jupyter_output>Range = 4
        
      * 
    * * 
  * * * 
* * * *<jupyter_text>20. Use lists to store the marks of 10 students and calculate their average<jupyter_code>l=[]
s=0
for i in range(1, 11):
    n=int(input("Student = "))
    l.append(n)
avg=sum(l)/len(l)
print()
print("Average score = ", avg)<jupyter_output>Student = 98
Student = 96
Student = 92
Student = 92
Student = 94
Student = 95
Student = 91
Student = 90
Student = 100
Student = 97

Average score =  94.5<jupyter_text>21. Implement linear search (using string data in the list)<jupyter_code>l=[]
print("Enter 5 names:")
for i in range(5):
    name=input()
    l.append(name)
print("Enter name you want to find:")
n=input()
c=0
p=1
for j in range(5):
    if n==l[j]:
        c=1
        p=j+1
if c==1:
    print("Found at position ", p)
else:
    print("Not found!")<jupyter_output>Enter 5 names:
aa
bb
cc
dd
ee
Enter name you want to find:
bb
Found at position  2<jupyter_text>22. Matrix multiplication<jupyter_code>X = [[12,7,3], [4 ,5,6], [7 ,8,9]]
Y = [[5,8,1,2], [6,7,3,0], [4,5,9,1]]
result = [[0,0,0,0], [0,0,0,0], [0,0,0,0]]

for i in range(len(X)):
   for j in range(len(Y[0])):
       for k in range(len(Y)):
           result[i][j] += X[i][k] * Y[k][j]
for r in result:
   print(r)<jupyter_output>[114, 160, 60, 27]
[74, 97, 73, 14]
[119, 157, 112, 23]<jupyter_text>23. Sort a list of integer (using bubble sort)<jupyter_code>def bubbleSort(arr):
    n = len(arr)
    for i in range(n):
         for j in range(0, n-i-1):
            if arr[j] > arr[j+1] :
                arr[j], arr[j+1] = arr[j+1], arr[j]
arr = [64, 34, 25, 12, 22, 11, 90]
 bubbleSort(arr)
 print ("Sorted array is:")
for i in range(len(arr)):
    print ("%d" %arr[i]),<jupyter_output>Sorted array is:
11
12
22
25
34
64
90<jupyter_text>24. Implement binary search(consider the list is already sorted)<jupyter_code>def binary_search(alist, key):
    start = 0
    end = len(alist)
    while start < end:
        mid = (start + end)//2
        if alist[mid] > key:
            end = mid
        elif alist[mid] < key:
            start = mid + 1
        else:
            return mid
    return -1
alist = input('Enter the sorted list of numbers: ')
alist = alist.split()
alist = [int(x) for x in alist]
key = int(input('The number to search for: '))
index = binary_search(alist, key)
if index < 0:
    print('{} was not found.'.format(key))
else:
    print('{} was found at position {}.'.format(key, index+1))<jupyter_output>Enter the sorted list of numbers: 4 5 6 7 8 9 10 11 12 13 14 15
The number to search for: 13
13 was found at position 10.
{'fraction_non_alphanumeric': 0.16953110405380162, 'fraction_numerical': 0.08191668223426116, 'mean_word_length': 3.6898817345597896, 'pattern_counts': {'":': 0, '<': 102, '<?xml version=': 0, '>': 114, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '28', 'dir': 'jupyter-structured-clean-dedup', 'id': '468339', 'license': 'MIT', 'n_tokens_mistral': 4946, 'n_tokens_neox': 4445, 'n_words': 1214, 'path': 'Basics - Advanced DAA [Lab] Assignment.ipynb', 'repo_name': 'Not-A-Builder/uni-lab', 'size': '10711'}