Arrays Grade08
Arrays Grade08
Anjan Mahanta
[email protected]
List | Working with multiple
records
2
Formatting the output
3
10.2 Arrays
5
10.2.1 One Dimensional Arrays
6
Pseudocode
OUTPUT "Enter these 9 values in order 27, 19, 36, 42, 16, 89, 21, 16,
55"
7
Python
8
Dynamic Array
9
Dynamic Array
a=[]
size=int(input("Please enter the size of the array:
"))
for i in range(size):
value=int(input("Enter the values: "))
a.append(value)
print("The list of array: ", a)
10
Search for a value
#Create an array
a=[]
size=int(input("Please enter the size of the array: "))
for i in range(size):
value=int(input("Enter the values: "))
a.append(value)
print("The list of array: ", a)
list=["A","B","C","B"]
flag=0
find=input("Enter the search element: ")
for i in range(len(list)):
if find==list[i]:
print("Found at ",i)
flag=1
if flag!=1:
print("Not Found")
12
Linear Search | Dynamic
list=[]
n=int(input("Enter the length of array: "))
for i in range(n):
array_element=input("Enter the element: ")
list.append(array_element)
print(list)
flag=0
find=input("Enter the search element: ")
for i in range(len(list)):
if find==list[i]:
print("Found at ",i)
flag=1
if flag!=1:
print("Not Found")
13
Sorted Array
#Create an array
a=[]
size=int(input("Please enter the size of the array: "))
for i in range(size):
value=input("Enter the values: ")
a.append(value)
print("The list of array: ", a)
#Sort the array
a.sort()
print("The shorted list is ",a) 14
Delete from a List
15
Problem | Adding to the list | Part 1
16
Solution | Adding to the list | Part 1
17
Solution | Adding to the list | Part 1
name1=input("Enter the name of somebody you want to invite to your party:
")
name2=input("Enter another name: ")
name3=input("Enter a third name: ")
party_list=[name1,name2,name3]
another=input("Do you want to invite another? (Y/N): ")
while another=="Y":
newname=party_list.append(input("Enter another name: "))
another=input("Do you want to invite another? (Y/N): ")
print("You have ",len(party_list), "people coming to your party!")
18
Solution | Adding to the list | Part 1
19
Problem | Adding to the list | Part 2
20
Solution | Adding to the list | Part 2
21
Solution | Adding to the list | Part 2
name1=input("Enter the name of somebody you want to invite to your party: ")
name2=input("Enter another name: ")
name3=input("Ehter a third name: ")
party_list=[name1,name2,name3]
another=input("Do you want to invite another? (Y/N): ")
while another=="Y":
newname=party_list.append(input("Enter another name: "))
another=input("Do you want to invite another? (Y/N): ")
print("You have ",len(party_list), "people coming to your party!")
selection=input("Enter one of the names: ")
print(selection, "is in position ", party_list.index(selection), "on the list")
stillcome=input("Do you still want them to come (Y/N): ")
if stillcome=="N":
party_list.remove(selection)
print(party_list) 22
Solution | Adding to the list | Part 2
23
10.2.2 Two Dimensional Arrays
24
10.2.2 Two Dimensional Arrays
25
Python
26
2 D Array | Challenge 1
27
2 D Array | Challenge 1
28
2 D Array | Challenge 2
29
2 D Array | Challenge 2
30
2 D Array | Challenge 3
31
2 D Array | Challenge 3
32
2 D Array | Challenge 4
33
2 D Array | Challenge 4
34
Dynamic 2 D Array
35