Software Programming: Understanding Variables, Lists, and Functions

Verified

Added on  2023/06/15

|9
|774
|436
Homework Assignment
AI Summary
This assignment solution provides a comprehensive overview of fundamental software programming concepts, focusing on variables, lists, and user-defined functions (UDFs). It explains how variables are used to store information, detailing data types and assignment in Python. Lists, which store multiple values, are explored with examples of accessing elements and utilizing built-in functions like append, insert, clear, sort, and index. The importance of UDFs in organizing code is highlighted, emphasizing their role in creating reusable functionalities and custom procedures. The solution also illustrates how UDFs can modify variable values through reference passing and provides a simple example of an addition function. Desklib offers this and many more solved assignments for students.
Document Page
SOFTWARE
PROGRAMMING
(PART 1)
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
TABLE OF CONTENTS
PART A...........................................................................................................................................3
A1. Variables and Lists................................................................................................................3
A2. User defined function and its importance to programming..................................................6
REFERENCES................................................................................................................................8
Document Page
PART A
A1. Variables and Lists
Variables are used by computer systems to store information. Using variables, we can
label a particular piece of information by specifying its type and naming it (Santos and Toffolo,
2020). In Python, a variable can be created and assigned a value by simply writing the name of
the variable, writing '=' after it and then writing the value that is to be assigned to it. For
example, in the following cases an integer value of '4' and a string type value of 'sally' is stored in
the variable 'x', respectively.
The data-type of the variable is to be specified in the following manner:
While variables in python can store only one value, Lists are used to store multiple values. For
example, the list, with the name of 'mylist', contains 3 variables, namely 'apple', 'banana' and
'cherry'.
To access the elements of the list, the function print() and the in-built function of list, thislist[]
are used in conjunction. Taking the example of a list named 'thislist', it is used as follows:
Document Page
After running the following code, the results are as follows:
5 built-in functions of a list are:
1. list.append(element) or append()
This built-in function of a list will add an element to the end of the list
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
2. list.insert(position, element) or insert()
This built-in function is used to insert a specified value at a specific position.
3. list.clear() or clear()
This function will delete all the elements contained in the list.
4. list.sort(reverse=True\False, key=myFunc) or sort()
The sort() function of a list will sort the list in the ascending order.
Document Page
5. list.index(element) or index()
Document Page
A2. User defined function and its importance to programming
It is defined as the functions that are required to arrange the code in a programming body.
User defined function (UDF) do not return the value as like the return parameters, as to returning
the value programmer can proceed to identify the result parameter in the declaration of the
function, after this allocate the values in the body function (Hunt, 2019). In such variables that
are passing through the function generally passed by the reference instead of the value.
Therefore, it implies that if there is any change in the variable value in the function than it
ultimately swap the variable value in usual scope.
Importance of UDF
For the programmer it is beneficial as it enables them to develop their own aspects and
procedures which their system follows. It is considered as the basic requirement of any coding
program. It can be easily called when there is need, as their syntax is mainly depends on the
coding languages. Apart from the programming language, UFD also consider as the function that
are used to develop the program in database management system (Gonzalez, 2020). It is
advantageous in term of reusing the functionality.
Steps:
First to define the function in this scenario, the chosen function is addition
def add():
After this considering the parameters which is a and b and assigning a value “10 to a ” and “5 to
b” and perform the addition function by using keyword that is “add” and lay out the output by
using output print function.
In this case the desired output will be-
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
sum=a+b
=10+5
=15 and this value is saved in “sum”.
Document Page
REFERENCES
Books and Journals
Gonzalez, A.J., 2020. Defining and Calling Functions. In Computer Programming in C for
Beginners (pp. 65-81). Springer, Cham.
Hunt, J., 2019. Functions in Python. In A Beginners Guide to Python 3 Programming (pp. 117-
131). Springer, Cham.
Santos, H.G. and Toffolo, T.A., 2020. Mixed Integer Linear Programming With Python.
chevron_up_icon
1 out of 9
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]