Sie sind auf Seite 1von 11

ASSIGNMENT #2

Rehmat Ullah
9800
# Task: 1.
# Write a pseudocode and Python program to input values into a table

# and print these values in tabular form. Draw a flowchart for the

# same.

Pseudocode:
Pre-Condition: Nested List
Post-Condition: None
Return: None

1. Start
2. Take a NestedList containing data
3. Print Headers for the table
4. Let i = 0
5. If i <= nestedlist
a. Print the table row vise
b. i = i + 1
6. Stop

Flowchart:
Python Program:
nestedlist = [["Rehmat Ullah",9800,3.94],

["Mujeeb Ullah",9996,2.47],
["Muhammad Adil",9797,3.63],

["Ikram",1234,3.00]]

print(": Name : Roll No. : CGPA :")

for i in nestedlist:

print(":",i[0]," "*(13-len(i[0])),

":",i[1]," "*(7-len(str(i[1]))),

":",i[2]," "*(4-len(str(i[2]))),":")

Output:

# Task: 2.
# Suppose you have arrays A and B, each with 10 integer values.

# Write a pseudocode and Python program to test that each element

# of Array A is equal to it corresponding element in Array B.

# Draw a flowchart for the same.

Pseudocode:
Pre-Condition: Two Arrays with 10 Integers
Post-Condition: None
Return: None

1. Start
2. Declare Array 1 and Array 2
3. Let i = 0
4. If i <= 10
a. Check whether Array1[i] == Array2[i]
b. Print True or False
5. Stop

Flowchart:

Python Program:
Array_A = [1,2,3,4,5,6,7,8,9,10]
Array_B = [2,3,5,4,7,6,6,2,5,10]

print("Array_A = ",Array_A)

print("Array_B = ",Array_B)

for i in range(10):

print(Array_A[i],"=",Array_B[i],":",Array_A[i]==Array_B[i])

Output:

# Task: 3.
# Write a pseudocode and Python program that reverses the elements

# of an array, so that the last element becomes the first, the second

# last becomes second and so on. Draw a flowchart for the same.

Pseudocode:
Pre-Condition: Array
Post-Condition: None
Return: None

1. Take an Array
2. Take an empty array which will be the reversed of original Array
3. Let i = -1
4. If i <= Negative of the length of original Array
a. Append array[i] to that empty array we defined earlier.
b. i = i – 1
5. Print Reversed Array
6. Stop

Flowchart:

Python Program:
array = [1,2,3,4,5]
print("Original Array = ",array)

reversed_array=[]

for i in range(-1,-(len(array))-1,-1):

reversed_array.append(array[i])

print("Reversed Array = ",reversed_array)

Output:

# Task: 4.
# Write a function in Python called Merge_Arrays() that takes two

# arrays and merge them into a single array.

Pseudocode:
Pre-Condition: None
Post-Condition: None
Return: None

1. Start
2. Define a function named as Merge_Arrays()
3. Take two arrays as parameters
4. Concatenate both Arrays into one
5. Print Merged Array
6. Stop

Flowchart:
Python Program:
def Merge_Arrays(a,b):

print("Array 1 = ",a)

print("Array 2 = ",b)

c=a+b

print("Merged Arrays = ",c)

size1 = int(input("Enter Size for Array 1: "))

array1 = []

for i in range(size1):

value = int(input("Enter any number: "))

array1.append(value)

size2 = int(input("Enter Size for Array 2: "))

array2 = []

for j in range(size2):

value = int(input("Enter any number: "))

array2.append(value)

Merge_Arrays(array1,array2)

Output: