Assignment 1 (LAB)
Assignment 1 (LAB)
Question 1:
Remove all the unnecessary tests from the nested conditional statement below.
Question 2:
You are given a String Code containing a message composed entirely of decimal digits (0~9). Each
digit consists of some number of dashes (see diagram below). You have to count the total number
of dashes in the whole number.
0- Consists of 6 dashes.
1- Consists of 2 dashes.
2- Consists of 5 dashes.
3- Consists of 5 dashes.
4- Consists of 4 dashes.
5- Consists of 5 dashes.
6- Consists of 6 dashes.
7- Consists of 3 dashes.
8- Consists of 7 dashes.
9- Consists of 6 dashes.
Examples:
13579 returns: 21 024268 returns: 28
Problem Based Learning Assignment
Question 3:
Write a program that asks the user to enter the number 𝑵 and then prints on the screen the
numbers 1 through 𝑵𝟐 arranged in a 𝑵𝒙𝑵 grid.
An example is shown below, where the user entered 4.
Enter a number: 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
HINT:
Solution can be achieved with or without the use of nested for loop.
Make use of extra feature of print command as shown in Figure 2
Question 4:
Data normalization is an application which is used to convert data of any range into a specific
range say between 0 to 1. This is done by first finding the minimum value from data and
subtracting that from each value. Then the whole data is divided by the maximum value of new
data. For example
If 𝑫𝒂𝒕𝒂 = {𝟑, −𝟏, 𝟎, 𝟗, 𝟏𝟎, 𝟐, 𝟏𝟑},
Then minimum value is: Mindata = -1
Analyze above given problem and use your knowledge about arrays to solve this problem. Your
program should ask user to enter 10 elements and print its normalized version as mentioned
above in example.
HINT:
The solution will contain multiple separate loops for different operations, e.g. loop 1 will get
input from user and create a list from it using example code segment shown in Figure 1.
Question 5:
Write a python script which finds the location of a target key from integer list entered by the
user. The user can enter a maximum of 10 integers and saves it in a list for processing.
Problem Based Learning Assignment
The code should determine whether the given target value occurs in any of the cells of the array,
and if it does, the code should return the subscript of the cell containing the target value. If more
than one of the cells contains the target value, then the code should return the largest subscript
of the cells that contain the target value. If the target value does not occur in any of the cells,
then the code should return the sentinel value -1.
Thus, for example, if the target value that's passed to the code is 34 and the array that's passed
to the code looks like this:
58 | 26 | 91 | 34 | 70 | 34 | 88
then the target value occurs in cells 3 and 5, so the code should return the integer value 5.
Helpful Command(s):
listName.append(newvalue)
print(variableName, end=” ”) # end controls whether new variable gets printed on same line or
a newline