0% found this document useful (0 votes)
14 views3 pages

Assignment 1 (LAB)

This document contains instructions for a problem-based learning assignment in computer organization with 5 questions. Question 1 asks to simplify a nested conditional statement checking income levels. Question 2 involves counting dashes in decimal digit representations. Question 3 has the user enter a number N and prints numbers 1 to N^2 in an N x N grid. Question 4 describes normalizing a data set by finding the minimum, subtracting it, then dividing by the maximum. Question 5 involves finding the index of a target value in a user-input integer list. Hints are provided for each question involving concepts like loops, arrays, and print formatting.

Uploaded by

Rameez Raja 10 F
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Assignment 1 (LAB)

This document contains instructions for a problem-based learning assignment in computer organization with 5 questions. Question 1 asks to simplify a nested conditional statement checking income levels. Question 2 involves counting dashes in decimal digit representations. Question 3 has the user enter a number N and prints numbers 1 to N^2 in an N x N grid. Question 4 describes normalizing a data set by finding the minimum, subtracting it, then dividing by the maximum. Question 5 involves finding the index of a target value in a user-input integer list. Hints are provided for each question involving concepts like loops, arrays, and print formatting.

Uploaded by

Rameez Raja 10 F
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Problem Based Learning Assignment

Computer Organization-LAB Assignment


DE-45 Computer Engineering

Question 1:
Remove all the unnecessary tests from the nested conditional statement below.

income = float(input("Enter your monthly income: "))


if (income < 0.0):
print"You are going farther into debt every month.")
elif (income >= 0.0 && income < 1200.00):
print"You are living below the poverty line.")
elif (income >= 1200.00 && income < 2500.00):
print"You are living in moderate comfort.")
elif (income >= 2500.00):
print"You are well off.")

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

After subtracting this from original Data then


NewData = Data - MinData = {𝟒, 𝟎, 𝟏, 𝟏𝟎, 𝟏𝟏, 𝟑, 𝟏𝟒},

Its maximum value is: MaxNewData = 14

NormalizedData = NewData / MaxNewData = {0.2857, 0, 0.0714, 0.7142, 0.7857, 0.2142, 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)

Figure 1 Example code and output based on append function.

print(variableName, end=” ”) # end controls whether new variable gets printed on same line or
a newline

Figure 2 Alternate behavior of print command

You might also like