HS1031 Introduction to programming

Student Number: (enter on the line below)

AssignmentTutorOnline

Student Name: (enter on the line below)

HS1031
Introduction to programming
final assessmeNt

Trimester 1, 2021

Assessment Weight:       40 total marks

Instructions:

  • All questions must be answered by using the answer boxes provided in this paper.
  • Completed answers must be submitted to Blackboard by the published due date and time.

    Submission instructions are at the end of this paper.

Purpose:
This assessment consists of six (6) questions and is designed to assess your level of knowledge of the key topics covered in this unit

Question 1                                                                                                    ( 6 marks)

Multiple Choice Questions

Please write the letter of the correct answer in the third column of the table below (i.e. a, b, c, or d).

QuestionAnswer
1
2
3
4
5
6
Total 

How many time this program will run?

Question 2                                                                                                    (6 marks)

Case Study

Sandeep is a nascent Python developer. He has been asked by his manager to use functions in his code whenever possible. However, Sandeep feels that using functions is a waste of time. Provide three reasons to convince Sandeep to start using functions in his scripts.

ANSWER:  ** Answer box will enlarge as you type

Question 3                                                                                                    (6 marks)

For each of the following code snippets, explain: (i) what does the code do? And (ii) What is the expected output?

(1)

(2)

ANSWER: 

(1)

(2)

Question 4                                                                                                    (6 marks)

Consider the following code snippet.

Answer the following questions:

(a) What do you think the purpose of this program is?

(b) What does the statement in Line 4 do?

(c) What does the code in Line 12 achieve?

(d) What happens if the print statement in Line 16 is moved a tab forward (i.e. aligned with the if-else statement in lines 12 & 14)?

ANSWER: 

(a)

(b)

(c)

(d)

Question 5                                                                                                    (8 marks)

Countries

The attached text file (countries.txt) includes a list of countries in a non-specific order. Furthermore, many of these countries are repeated in the file. You were asked by your company to produce a list of world’s.

Write a Python code to retrieve data from the file and print out the unique names of countries a descending order. Your program should prompt the users to determine whether the list should be printed in ascending or descending order. Save your file as countries.py (make sure to include it in your submission).

ANSWER: 

Python script

Question 6                                                                                                    (8 marks)

Python language provides various built-in functions which can be used by programs without worrying about the code. One of the most frequently used built-in functions in Python is the range function.

Answer the following questions:

(a) Explain what does the range function do.

(b) The range function has three arguments: start, stop and step. Describe the function of each of these arguments.

(c) Develop a function (name it uRange(start,stop,step)) which imitates Python’s range function. uRange take at least one argument (stop) and maximum of three.

  • If only one argument is passed to uRange, it is assumed to be the ‘stop’. Start takes zero, while step is equated to one.
  •  If two arguments are passed to uRange, those would be ‘start’ and ‘stop’. Start takes zero, while step is equated to one. Step is equal to one by default.
  • If three arguments are passed to uRange, those would be ‘start’, ‘stop’ and ‘step’.

Use None as a default value for the second and third parameters. So the first part of the function definition determines what the parameters are, whilst the rest of the code uses the values of these parameters to generate a sequence of numbers counting up or down (in the form of list).

See below examples for the output:

ANSWER: 

(a)

(b)

(c) Python script

END OF FINAL ASSESSMENT

Submission instructions:

  • Save your answers in the the answer boxes provided in this paper, including your Python code. Save your file with your STUDENT ID NUMBER and UNIT CODE e.g. EMV54897 HS1031
  • This file must be saved in MICROSOFT WORD FORMAT ONLY
  • For answers that involves Python script, make sure to also save your code in .py file format.
  • Place ALL your submission files (MS Word + Python files) in one folder (again, with your STUDENT ID NUMBER and UNIT CODE e.g. EMV54897 HS1031), and convert the folder into a ZIP file (RAR format is NOT acceptable)
  • Upload your submission to the appropriate link on Blackboard
  • Only one submission is accepted. Please ensure your submission is the correct document (this would be your ZIP file).
  • All submissions are automatically passed through SafeAssign to assess academic integrity.

GET HELP WITH YOUR PAPERS

GET THIS ANSWER FROM EXPERTS NOW

WhatsApp
Hello! Need help with your assignments? We are here
Don`t copy text!