EEE385 - Lab - 1.ipynb - Colab
EEE385 - Lab - 1.ipynb - Colab
Variables can store data of different types, and different types can do different things. Python has the following data types built-in by default:
keyboard_arrow_down Strings
A string is a series of characters, surrounded by single or double quotes
x = 20
y = 20.5
z = (2+1j)
<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
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
equal --> ==
NOT equal --> !=
greater than or equal --> >=
less than or equal --> <=
if-else statements
if condition:
elif condition
statements
else:
statements
keyboard_arrow_down TASK 2
Implement BracU Grading scheme using conditional statements
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
statements
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-
list learning
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