BN108 Programming for Networking

This assignment is divided into two components. The first component (Part A) focuses on the design and analysis phase to solve simple problems. The second component (Part B) is focused on applying basic control structures and functions. Part A is Due in Week 3 and Part B in Week 8. A report is to be submitted for both parts separately on the respective Moodle links.

PART A: Problem Solving, Expressions, and Operations

  1. How does a computer understand a programming language?
  2. Computer programming can be divided into three distinct areas of activity:
  • Problem definition and requirement gathering
  • Creating a structured solution (or algorithm)
  • Coding (e.g. Java, Python, C++)

For the given problem definition, provide a structured solution (or algorithm):

A student wants to submit an assignment on Moodle for unit BN108. The assignment file is stored on the Desktop folder in her/his laptop. Currently, the laptop is powered off.

3. When you’re writing long numbers, you can group digits using underscores to make large numbers
more readable:

universe_age = 20_000_000_000
Print the above variable on the python shell prompt.
Add 12 billion to it and print the result.

A student has to enroll in a unit at your institute, XIT. To be eligible for enrolments, XIT checks for various requirements, such as did s/he pass pre-requisites with a minimum grade of ‘P’ etc. You may include any other requirement(s) also. In the example,

  • What are the knowns and the unknowns?
  • Where, if anywhere, is there ambiguity?
  • What assumptions have you made about the problem?
  • Provide a structured solution (algorithm):

5. Write statements in python for the following math equations: 𝑦𝑦 = √12.3𝑥𝑥4 − 9.1𝑥𝑥3 − 4.6𝑥𝑥 + 34.2 Evaluate the above expression at the following values of variable x: x =2, x =-2

6. Test and justify the output of the following expressions: a. (2 * (10 % 5)) b. 9/34+6%22/2*3.

PART B – Algorithms and Functions

  1. A text analyst wants to analyze a text file (refer to File.txt on Moodle). She wants to find out the total number of sentences in the text file. She would also like to know if there are acronyms in the text file and keep a count of them so that she can improve the text file later. “Computational thinking is a way of thinking about problem-solving that grew out of computer science. With computational thinking, we learn how to break problems down, create algorithms to solve them and generalize those solutions so we can solve even bigger problems. Often, though, we want to teach a computer to execute those algorithms for us, and that’s where coding comes in.”_[1]
  • Write a detailed algorithm and illustrate the problem design with the help of a flowchart to count the total number of sentences and acronyms in the text file. 6+6 Marks
  • Write a program in python that takes the text file as input and displays the count of sentences as well as acronyms in it. 8 MarksBN108 Programming for Networking Page#4 of 5 Prepared by Dr. Huma Chaudhry Moderated by: Prof. Paul Kwan March 2021

2. A list is made from zero or more elements, separated by commas and surrounded by square brackets. Refer to the following examples of lists: 10 Marks

  • Pick a list of your choice from the examples above. State why you chose it.
  • You can extract a single member from a list by specifying its offset. Get the second member from your list.
  • The append function can add a new member/value into a list! Add your MIT ID in your list from 2a
  • Combine the list of your choice with another list.
  • e. A negative index can help you easily reverse a list [::-1]. Reverse your new list while skipping every second member. e.g. leap_years = [2000, 2008]

This question assesses your knowledge of functions: 10 Marks

  • Write a Python function to sum all the numbers passed to it in a list. [44, 33, 22, 11]
  • Write a Python function that takes the result of 3a and returns its square.
  • Print the result of 3b in the main call. Refer to stub assignment1_partB_function.py

BN108 Programming for Networking

Leave a Comment

Open chat
Hi there!
How can I help you?