0% found this document useful (0 votes)
37 views5 pages

EEE385 - Lab - 1.ipynb - Colab

Uploaded by

anwarshadman.27
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views5 pages

EEE385 - Lab - 1.ipynb - Colab

Uploaded by

anwarshadman.27
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Name: Anwar Shadman

Student ID: 20321028

keyboard_arrow_down EEE385 (MACHINE LEARNING)


LAB 1: Introduction to Python

Different Types of Data in Python

Variables can store data of different types, and different types can do different things. Python has the following data types built-in by default:

Text Type: str


Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
None Type: NoneType

keyboard_arrow_down Strings
A string is a series of characters, surrounded by single or double quotes

1 print("Welcome to Machine Learning Course")

Welcome to Machine Learning Course

1 msg = " Welcome to Machine Learning Course "


2 print(msg)

Welcome to Machine Learning Course

Concatenation (combining strings)

1 First = "Welcome to "


2 Second = "Machine "
3 Third = "Learning Course"
4 print(First + ' ' + Second + ' ' + Third)

Welcome to Machine Learning Course

keyboard_arrow_down Numeric Data


1 x = 20 #int
2 print('x =' , x)
3 y = 20.5 #float
4 print('y =', y)
5 z = 2 + 1j #complex
6 print('z =', z)

x = 20
y = 20.5
z = (2+1j)

keyboard_arrow_down Getting the Data Type


1 x = 2 + 3j
2 print(type(x))

<class 'complex'>
keyboard_arrow_down Taking User Input
1 Name= input("Please input your name: ")
2
3 print('Welcome to First ML class ' + Name + " ! !")
4

Please input your name: Anwar


Welcome to First ML class Anwar ! !

keyboard_arrow_down TASK 1
Take input of two numbers (n1 & n2) and compute the following:

Addition
Subtraction
Multiplication
Division (n1 / n2 & n2 != 0)

1
2 n1 = input ("Enter the first number: ")
3 n2 = input ("Enter the Second number: ")
4
5 add = float(n1) + float(n2) # add
6 Sub = float(n1) - float(n2) # Sub
7 Mult = float(n1) * float(n2) # Mult
8 Div = float(n1) / float(n2) # Div
9
10 print ('Addition = ',add)
11 print ('Subtraction = ',Sub)
12 print ('Multipication = ',Mult)
13 print ('Division = ',Div)
14

Enter the first number: 15


Enter the Second number: 5
Addition = 20.0
Subtraction = 10.0
Multipication = 75.0
Division = 3.0

keyboard_arrow_down Conditional Statements


Conditional operators:

equal --> ==
NOT equal --> !=
greater than or equal --> >=
less than or equal --> <=

if-else statements
if condition:

statements if condition is TRUE

elif condition

statements

else:

statements

1 mark = float(input('Please enter mark: '))


2 if mark > 100:
3 print('Wrong input')
4 elif mark> 60:
5 print('Pass')
6 else:
7 print('Fail')

Please enter mark: 58


Fail
Multiple Condition checking

and --> TRUE if both conditions are met


or --> TRUE if any one condition is met

keyboard_arrow_down TASK 2
Implement BracU Grading scheme using conditional statements

1 marks = float (input('Please enter mark: '))


2
3 if mark > 100:
4 print('Wrong input')
5 elif marks>=97 and marks<= 100:
6 print('The Grade is: A+ ;Exceptional')
7 elif marks>=90 and marks<= 97:
8 print('The Grade is: A ;Excellent')
9 elif marks>=85 and marks<= 90:
10 print('The Grade is: A-')
11 elif marks>=80 and marks<= 85:
12 print('The Grade is: B+')
13 elif marks>=75 and marks<= 80:
14 print('The Grade is: B')
15 elif marks>=70 and marks<= 75:
16 print('The Grade is: B-')
17 else:
18 print('Fail :( ')

Please enter mark: 93


The Grade is: A ;Excellent

keyboard_arrow_down Loops
for loop
for i in range(N):

statments

1 for a in range(10):
2 a = a + 1 #give space and aling with print
3
4 print(a) # indexing starts from 0 in python

1
2
3
4
5
6
7
8
9
10

keyboard_arrow_down while loop


while condition:

statements

1 a = 1 #have to insert index no. in while loop


2
3 while a <= 10:
4 print(a)
5 a = a + 1

1
2
3
4
5
6
7
8
9
10

keyboard_arrow_down Task 3
take input of the marks of 5 students using loop and do the same thing as task 2

1 for i in range(5):
2 marks = float(input("Enter a Number: "))
3 if mark > 100:
4 print('Wrong input')
5 elif marks>=97 and marks<= 100:
6 print('The Grade is: A+ ;Exceptional')
7 elif marks>=90 and marks<= 97:
8 print('The Grade is: A ;Excellent')
9 elif marks>=85 and marks<= 90:
10 print('The Grade is: A-')
11 elif marks>=80 and marks<= 85:
12 print('The Grade is: B+')
13 elif marks>=75 and marks<= 80:
14 print('The Grade is: B')
15 elif marks>=70 and marks<= 75:
16 print('The Grade is: B-')
17 else:
18 print('Fail :( ')
19

Enter a Number: 98
The Grade is: A+ ;Exceptional
Enter a Number: 87
The Grade is: A-
Enter a Number: 83
The Grade is: B+
Enter a Number: 78
The Grade is: B
Enter a Number: 71
The Grade is: B-

keyboard_arrow_down List (like array in C programming)


list_name = [val_1, val_2, val_3, .......]

1 marks = [88, 56, 94, 92, 76]


2 print(marks)

[88, 56, 94, 92, 76]

list learning

1 marks = [88,-56, 94,82, 94]


2 print(marks)
3
4 marks. append(110) #append = add no.
5 print(marks)
6
7 marks.insert(-2,125) #first e position number=-5 (88 is -5) and then which number=125
8 print(marks)
9
10 marks.remove(94) #removes the value as PEr VALUE
11 print(marks)
12
13 marks.pop(1) #removes the value as per index number
14 print(marks)
15

[88, -56, 94, 82, 94]


[88, -56, 94, 82, 94, 110]
[88, -56, 94, 82, 125, 94, 110]
[88, -56, 82, 125, 94, 110]
[88, 82, 125, 94, 110]

keyboard_arrow_down task 4
store the marks of 5 students in a list and then show their grades

1 marks= [92,82,74,88,89]
2
3 i=1 #index to start
4 for mark in marks:
5 print('The marks of Student-{} is {}'.format(i, mark))
6 if mark>=90 and mark<=100:
7 print('The Grade is: A')
8 elif mark>=85 and mark<=90:
9 print('The Grade is: A-')
10 elif mark>=80 and mark<=85:
11 print('The Grade is: B+')
12 elif mark>=75 and mark<=80:
13 print('The Grade is: B')
14 elif mark>=70 and mark<=75:
15 print('The Grade is: B-')
16 else:
17 print('Wrong Input')
18
19 i= i+1
20

The marks of Student-1 is 92


The Grade is: A
The marks of Student-2 is 82
The Grade is: B+
The marks of Student-3 is 74
The Grade is: B-
The marks of Student-4 is 88
The Grade is: A-
The marks of Student-5 is 89
The Grade is: A-

You might also like