You are on page 1of 8

Introduction To Machine Learning

LAB REPORT # 1
Semester “5th “
Section “B”

Submitted To: Sir Ameer Hamza

Submitted By:

Muhammad Masab

20-cs-033

DEPARTMENT OF COMPUTER SCIENCE HITEC UNIVERSITY, TAXIL.


1. Objective:

The objective of this lab to download and install python with Jupiter
notebook and revision of python concepts.

2. Software Tool: -

Jupiter Notebook/weka

Lab Task

I. Write a Python program to calculate interest?


Formula: Interest = (principal x rate of interest x time)/100?
Code:
principal = float(input('Enter the principle amount: '))
time = float(input('Enter the time: '))
rate = float(input('Enter the rate: '))
simple_interest = (principal*time*rate)/100
print("Simple interest is:", simple_interest)

Output:
Enter the principle amount: 10000
Enter the time: 5
Enter the rate: 5
Simple interest is: 2500.0
Explanation:
II. Write a program to create, concatenate and print a string and accessing substring

from a given string.

Code:
def subString(s, n):
   
    for i in range(n):
        for len in range(i+1,n+1):
            print(s[i: len]);

s = "abcd";
subString(s,len(s));

Output:

a
ab
abc
abcd
b
bc
bcd
c
cd
d
Explanation:
III. Write a python program to find largest of three numbers.
Code:
num1 = 10
num2 = 14
num3 = 12

if (num1 >= num2) and (num1 >= num3):
   largest = num1
elif (num2 >= num1) and (num2 >= num3):
   largest = num2
else:
   largest = num3

print("The largest number is", largest)

Output:

The largest number is 14


Explanation:
IV. Write a python program to that accepts length of three sides of a triangle as inputs.

The program should indicate whether or not the triangle is a right-angled triangle.

Code:

print("Input three integers(sides of a triangle)")
int_num = list(map(int,input().split()))
x,y,z = sorted(int_num)
if x**2+y**2==z**2:
    print('Yes')
else:
    print('No')

Output:
Input three integers (sides of a triangle)
676
No
Explanation:
V. Write all the above examples and show the output.

a) Write a program which can perform ADD, Subtract, Multiply and Divide
operations with the help of Functions. Multiply Function should be parametrized
function and other functions should be default functions.
Code:

def function():
  
  c=a+b
  d=a-b
  x=a/b
  print(" ADD: ",c,"\n Subtract: ",d,"\n Division: ",x)
  
print("Enter First Number: ")
a=float(input())
print("Enter Second Number: ")
b=float(input())
function()

def multiply(a,b):
  c =int(a) * int(b)
  print("\n MULTIPLIED result: ",c)
multiply(2,3)

Output:
Enter First Number:
3
Enter Second Number:
3
ADD: 6.0
Subtract: 0.0
Division: 1.0

MULTIPLIED result: 6
Explanation:

b) Write a python program which get two inputs from the user and calculate the
average of these numbers. The average function should be implemented as a
function.
Code:
#Average of two numbers 
a = input("enter first number") 
b = input("enter second number") 
a = float(a) 
b = float(b) 
print((a+b)/2)

Output:
enter first number3
enter second number5
4.0
Explanation:
Conclusion:

You might also like