0% found this document useful (0 votes)
10 views5 pages

Assignment 1 (LAB)

Uploaded by

salmanahmad2905
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)
10 views5 pages

Assignment 1 (LAB)

Uploaded by

salmanahmad2905
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/ 5

Problem Based Learning Assignment

Applications of ICT-LAB Assignment


DE-46 Computer Engineering
Submission Deadline: 09th November 2024, 11:59 P.M.
Problem Based Learning Assignment in Python

Instructions:

Grace Days: This assignment has 1 grace day associated with it.

Submission: Assignment is to be submitted on LMS in a .zip or .rar file. The folder should contain
a report in .pdf format showing the code output and the .py files for all the tasks.

Viva: No viva will be conducted for this assignment.

Queries: In case of queries, please contact in person or email at [email protected].

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:
Genetic algorithm is one of the algorithms that can be used for optimization problem. Two sub-
steps of this algorithm are:
1. We take two sub-portions of two equal sizes lists and create a third list using those sub-
portions.
2. We randomly change one of the value in the array that we got in step 1.
To further illustrate the above, consider the example below:
List 1:
1 2 3 4 5 6
Problem Based Learning Assignment

List 2:
11 12 13 14 15 16

Output List after Step 1:


1 2 3 14 15 16

Output List after Step 2:


1 2 84 14 15 16

Write a python program that takes input of two lists of same length n and performs the above two
steps. Both the output lists should be displayed at the end.
Hint: random value can be generated using a package in Python or can be taken as input from the
user.

Question 3:
Sorting of lists is required in many applications. There are several algorithms that can be used for
sorting offering different advantages and disadvantages. One of these algorithms is the selection
sort algorithm. Simply put, the selection sort algorithm searches for the smallest element in the
array and brings it to the first position by swapping. Now, we search for the second smallest
element in the array and bring it to second position in the array by swapping.

A step-by-step example is given below for an array with 5 elements:


Problem Based Learning Assignment
Problem Based Learning Assignment

Write a Python program that takes a list of length n and sorts the list using selection sort. The
unsorted and sorted list should be displayed. DO NOT USE THE BUILT IN SORT FUNCTION.

Question 4:
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

Question 5:

As a crude form of hashing, Lars wants to sum the digits of a number. Then he wants to sum the
digits of the result and repeat until he has only one digit left. He learnt that this is called the digital
Problem Based Learning Assignment

root of a number. For example, if the number is 187 then adding the digits (1 + 8 + 7) would give
16. 16 still has two digits so the process would be repeated (1 + 6). This would give 7 which is a
single digit and hence the process is stopped.

Your job is to help Lars by writing a Python Program that takes a number as input from the user
and returns the digital root of that number.

You might also like