Professional Documents
Culture Documents
Lec 3 4
Lec 3 4
Department of Mathematics
Institute of Business Administration.
Yousuf Tufail ¯ Yousuf Tufail
ytufail@iba.edu.pk
Lecture 3 & 4
Solution
Solution
print(fam heights new[0])
Solution
print(fam heights new[0])
[’John’, 1.64]
Solution
print(fam heights new[0])
[’John’, 1.64]
print(fam heights new[2])
Solution
print(fam heights new[0])
[’John’, 1.64]
print(fam heights new[2])
[’mom’, 1.56]
Solution
print(fam heights new[0])
[’John’, 1.64]
print(fam heights new[2])
[’mom’, 1.56]
Example
Find the fourth element from the given list using python.
Example
Find the fourth element from the given list using python.
Solution
Example
Find the fourth element from the given list using python.
Solution
print(fam heights new[3])
Example
Find the fourth element from the given list using python.
Solution
print(fam heights new[3])
[’dad’, 1.80]
Example
Find the fourth element from the given list using python.
Solution
print(fam heights new[3])
[’dad’, 1.80]
Example
Find the fourth element from the given list using python.
Solution
print(fam heights new[3])
[’dad’, 1.80]
Example
Find the fourth element from the given list using python.
Solution
print(fam heights new[3])
[’dad’, 1.80]
Example
Find the fourth element from the given list using python.
Solution
print(fam heights new[3])
[’dad’, 1.80]
Example
Find the fourth element from the given list using python.
Solution
print(fam heights new[3])
[’dad’, 1.80]
When you write [0:n] for the selection in python, it means 0 (which
represent the first position) is included.
When you write [0:n] for the selection in python, it means 0 (which
represent the first position) is included. But n (which represent the n+1
position) is not included.
When you write [0:n] for the selection in python, it means 0 (which
represent the first position) is included. But n (which represent the n+1
position) is not included. Therefore [0:n] means select all the positions
from 0 to (n-1).
When you write [0:n] for the selection in python, it means 0 (which
represent the first position) is included. But n (which represent the n+1
position) is not included. Therefore [0:n] means select all the positions
from 0 to (n-1). i.e., [0:3] means select all the positions from 0 to 2.
When you write [0:n] for the selection in python, it means 0 (which
represent the first position) is included. But n (which represent the n+1
position) is not included. Therefore [0:n] means select all the positions
from 0 to (n-1). i.e., [0:3] means select all the positions from 0 to 2.
Solution
print(fam heights new[0:3])
When you write [0:n] for the selection in python, it means 0 (which
represent the first position) is included. But n (which represent the n+1
position) is not included. Therefore [0:n] means select all the positions
from 0 to (n-1). i.e., [0:3] means select all the positions from 0 to 2.
Solution
print(fam heights new[0:3])
[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56]]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 6 / 10
Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Example
Find the first two values from the given list.
Example
Find the first two values from the given list.
Solution
Example
Find the first two values from the given list.
Solution
print(fam heights new[0:2])
Example
Find the first two values from the given list.
Solution
print(fam heights new[0:2])
[[”John”, 1.64], [”Hazel”, 1.42]]
Example
Find all the values in the given list except first value.
Example
Find all the values in the given list except first value.
Solution
Example
Find all the values in the given list except first value.
Solution
There are two ways to solve it: Method 1:
Example
Find all the values in the given list except first value.
Solution
There are two ways to solve it: Method 1:
print(fam heights new[1:4])
Example
Find all the values in the given list except first value.
Solution
There are two ways to solve it: Method 1:
print(fam heights new[1:4])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Example
Find all the values in the given list except first value.
Solution
There are two ways to solve it: Method 1:
print(fam heights new[1:4])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Second Method:
Example
Find all the values in the given list except first value.
Solution
There are two ways to solve it: Method 1:
print(fam heights new[1:4])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Second Method:
print(fam heights new[1:])
Example
Find all the values in the given list except first value.
Solution
There are two ways to solve it: Method 1:
print(fam heights new[1:4])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Second Method:
print(fam heights new[1:])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Example
Find all the values in the given list except first value.
Solution
There are two ways to solve it: Method 1:
print(fam heights new[1:4])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Second Method:
print(fam heights new[1:])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Example
Find all the values in the given list except first value.
Solution
There are two ways to solve it: Method 1:
print(fam heights new[1:4])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Second Method:
print(fam heights new[1:])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Solution
There are two ways to solve it: Method 1:
print(fam heights new[1:4]
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Second Method:
print(fam heights new[1:])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Max/min Function
Suppose A=[1, 3, 7, 11, 9, 2]
print(max(A))
11
Max/min Function
Suppose A=[1, 3, 7, 11, 9, 2]
print(max(A))
11
print(min(A))
Max/min Function
Suppose A=[1, 3, 7, 11, 9, 2]
print(max(A))
11
print(min(A))
1
Max/min Function
Suppose A=[1, 3, 7, 11, 9, 2]
print(max(A))
11
print(min(A))
1
Round function
Max/min Function
Suppose A=[1, 3, 7, 11, 9, 2]
print(max(A))
11
print(min(A))
1
Round function
a=4.76
Max/min Function
Suppose A=[1, 3, 7, 11, 9, 2]
print(max(A))
11
print(min(A))
1
Round function
a=4.76
print(round(a))
Max/min Function
Suppose A=[1, 3, 7, 11, 9, 2]
print(max(A))
11
print(min(A))
1
Round function
a=4.76
print(round(a))
5
Max/min Function
Suppose A=[1, 3, 7, 11, 9, 2]
print(max(A))
11
print(min(A))
1
Round function
a=4.76
print(round(a))
5
print(round(a, 1))
Max/min Function
Suppose A=[1, 3, 7, 11, 9, 2]
print(max(A))
11
print(min(A))
1
Round function
a=4.76
print(round(a))
5
print(round(a, 1))
4.8