Programming Fundamentals: A Practical Guide to Problem Solving and Debugging

Verified

Added on  2024/05/21

|36
|3793
|212
AI Summary
This report delves into the fundamental concepts of programming, exploring various programming paradigms, including procedural, object-oriented, and event-driven programming. It provides a practical guide to problem-solving, algorithm design, and debugging techniques. The report includes a series of programming problems with detailed solutions, demonstrating the application of different programming paradigms and debugging tools. It also emphasizes the importance of coding standards and their role in creating robust and maintainable software.

Contribute Materials

Your contribution can guide someone’s learning journey. Share your documents today.
Document Page
Programming (L4)

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
Contents
INTRODUCTION.................................................................................................................................3
Lo1........................................................................................................................................................4
P1......................................................................................................................................................4
M1.....................................................................................................................................................4
D1......................................................................................................................................................4
LO2.......................................................................................................................................................6
P2......................................................................................................................................................6
M2.....................................................................................................................................................7
D2......................................................................................................................................................8
LO3.......................................................................................................................................................9
P3......................................................................................................................................................9
M3...................................................................................................................................................21
D3....................................................................................................................................................25
LO4.....................................................................................................................................................27
P4.....................................................................................................................................................27
P5.....................................................................................................................................................31
M4...................................................................................................................................................32
D4....................................................................................................................................................32
CONCLUSION...................................................................................................................................34
REFERENCES....................................................................................................................................35
1
Document Page
List of Figures
Figure 1 Problem 1.1.............................................................................................................................9
Figure 2Problem 1.2............................................................................................................................10
Figure 3Problem 1.3............................................................................................................................10
Figure 4Problem 1.4............................................................................................................................11
Figure 5 Problem 1.5...........................................................................................................................11
Figure 6 Problem 1.6...........................................................................................................................12
Figure 7Problem 1.7............................................................................................................................13
Figure 8 Problem 1.8...........................................................................................................................13
Figure 9 Problem 1.9...........................................................................................................................14
Figure 10Solution 1.1..........................................................................................................................14
Figure 11Solution 1.2..........................................................................................................................15
Figure 12Solution 1.3..........................................................................................................................15
Figure 13Solution 1.4..........................................................................................................................16
Figure 14Solution 1.5..........................................................................................................................17
Figure 15Solution 1.6..........................................................................................................................17
Figure 16Solution 1.7..........................................................................................................................18
Figure 17Solution 1.8..........................................................................................................................19
Figure 18Solution 1.9..........................................................................................................................20
Figure 19MENU..................................................................................................................................20
Figure 20IDLE....................................................................................................................................22
Figure 21IDLE....................................................................................................................................23
Figure 22About IDLE..........................................................................................................................24
Figure 23Debug IDLE.........................................................................................................................25
Figure 24Program file to debug...........................................................................................................28
Figure 25Program file to debug...........................................................................................................28
Figure 26Setting Breakpoints..............................................................................................................30
Figure 27After breakpoint, the line turns yellow.................................................................................30
Figure 28 Control window of debugging.............................................................................................31
2
Document Page
INTRODUCTION
This report presents the small problems conclude in a menu type which helps to execute all functions
easily in a one go through by selecting an optionfrom the menu to run which problem. Top achieve
passing grades, defining all the topics along description helps to understand easily to anyone. The
main objective of this report is to prepare a program which givesa basic understanding of knowledge
using a programming language and following programming paradigms fulfilling the requirements of
the program. In this, applying some modules which enable the operations performed on identifiers and
run the functions to execute code. This file representing modules done by programming language and
their procedures which help identify the code easily.
3

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
Lo1
Algorithm provides a step wise step detailed solution to solve a problem. Algorithm helps in data
processing, instruct how to make calculations and also used in other mathematical calculation.
P1
a) ALGORITHM 1.7
1) Start the python idle
2) Define functions for calculating and defining the elements
3) First, make defsumofarrayelements() function with an argument to define values
4) The express sum of an array element using for loop in the result variable
5) Return result which adds all the elements and produces output
6) Again make another function which defines array elements defarr()
7) Pass the values to an array
8) Last print the sum of the array by calling the function
9) Exit
M1
Steps were taken to execute code from writing 1.8
1) First, start the idle to open a new file for writing source code
2) Then make the function to run the program, which is very helpful to execute the code
3) Define start height by taking input from the user and also set minimum height limit to 0.5
as given
4) Set howmanyboumce to 0 which will be increment later by checking the condition
5) Now make a condition which checksstartheight to minimum height limit if it is less than
start height then increment howmanybounce by 1
6) Calculate start height by multiply 0.70 to start height
7) Last print the howmanybounces which give the bounces time
8) Exit
D1
Algorithm 1.9 a)
1) Start the program in python language
2) Import math library for mathematical calculation and define a function to execute this
program defmathsquiz()
4
Document Page
3) Take input for no of question from a user in integer and set out from program to False
4) Also, set playnoques and scoregame to 0 which will increment later in this code
5) Define operator array using +, -, *, / for check the solution to user solution
6) Make a while condition which runs until out of program is equal to false
7) Now generate operation through randomly from operation array
8) Check if the condition for playnoques is less than number of question or playnoques
should be greater or equal to 0
9) Then generate questions number 1 and 2 from random range 1 to 10
10) Print the generate number 1, operation, and generate number 2 and take input for user
solution from the userto verify the solution and increment playnoques to 1
11) Now check for all operations performed using if else conditional loop, if the solution will
match with user solution then print correct answer else print incorrect answer and the
correct answer is this.
12) After checking all condition come out of the program and set to true and return
completed your game and your final score is which is calculated
13) Exit
b)
The relation between code algorithm and code variant is just of the language difference. In the
algorithm, we write the code functionality and how it’ll work in the coding language in the normal
description like a paraphrase of source code and code is just a programming language in which we are
performing or executing the problem by compiling and executing the values by standard functions or
libraries of programming language.
5
Document Page
LO2
P2
Procedural programming language
The first programming paradigm that is likely to learn is procedural or imperative programming
which consists of module and data that operates on data information. In this programming,Procedures
are like mini-programs that can be called from anywhere else in the overall program.
Procedure programming computer programs is a programming paradigms in light of methodology
brings in which explanations are organized in subroutines or capacities which are regular systems, this
is procedural paradigm programming.
Object-orientedprogramming language
In Object-oriented paradigm, program or source is built on objects and an object is an instance of the
class. Object-oriented programming consists of data encapsulation, data hiding, abstraction and
inheritance which help in the program to execute and hide some data part from the viewer which is
not needed to see but work normally in the program. The best thing about object-oriented programs is
that we people are extremely used to considering objects. The use of the object model to show causes
considerably to create complex projects and object orientation diminishes the dangers of
programming software development.
Event Drivenprogramming language
In Event-driven programming paradigm, programs are executed in response to events like click,
keyboard key press or any device attaching which works for the event. The fundamental thought in
event-driven programming is that the program which is intended to respond to functions or code.
Hypothetically, all programming languages support the function driven style of programming,
although some language highlights, for example, terminations, make it less demanding to actualize.
Characteristics of procedural
It concentrates mainly on functions, but not on data.
Problem is isolated into sub-problems i.e. program is separated into a few littler projects
called functions.
In this, functions dstrbute global data information which is used in programs to use variables
No security to information moves straightforwardly among the capacities.
6

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Function changes information from one type to another.
It is based on top-downmethodology.
Characteristics of object-oriented
Encapsulation: It means you can combine data and code which manipulates into a single unit
which is commonly referred as encapsulated data.
Polymorphism: It means which have many forms such as poly means “many” allowsthe
object processed with different data types or classes.
Inheritance: It means reusability of existing classes such as a parent is used to child class and
its objects which perform some functions.
Abstraction: It is a concept which extracts the important information from an object by
eliminating unnecessary information.
Characteristics of Event-driven paradigm
Service-oriented means provides services which are available on a network so the code has
not to be rewritten again and again
Time-driven means relies on time i.e., work until timer off such as traffic light.
Event handlers mean code that relates to event form like a mouse click, a key press on the
keyboard.
Trigger functions decide what causes the event to take place or not.
Some other is simplicity, flexibility, ease of development, etc.
Python fits in all paradigms such as event-driven by clicking events, object-oriented by using classes
which helps to make more than 2 functions in a single class and procedural also by using small
modules in a single unit.
M2
An integrated development environment (IDE) is a product suite that combines the fundamental
devices developers need to compose and test programming. Normally, an IDE contains a code
rewriter, a compiler or translator and a debugger that the designer gets to through a solitary graphical
UI (GUI). An IDE might be an independent application, or it might be incorporated as a component of
at least one existing and good applications.
Some features are as follows:
7
Document Page
1) Code editorial manager: the surrounding where the user can compose code is known as the shell.
The code rewriter is content alter region that enables developer to compose, alter and spare a record of
code.
2) Auto-completion (or code fulfilment): This is intended to spare time while composing code.
3) Bracket coordinating: This is utilized for dialects that utilization sets of sections to stamp out
squares of code.
4) Syntax checks: This perceives the off-base utilization of linguistic structure and features any
blunders.
5) Translator: This gathers or translates the code.
6) Libraries: These give capacities that are excluded in the centre piece of the programming dialect.
7) Debugger: This is a program inside the IDE that is utilized to identify mistakes.
8) Runtimemistakes: They are blunders which will make the program or PC crash regardless of
whether there gives off an impression of being nothing amiss with the program code.
9) Syntaxblunders: They are mistakes in how the code is composed. Interpreters can just execute a
program on the off chance that it is grammatically right. Basic sentence structure blunders incorporate
spelling mistake, wrong utilization of accentuation and the utilization of capital letters.
D2
On evaluating the program code of an application software which applies the all programming
paradigms in term of source code format or characteristics by applying class and its objects used from
object-oriented programming paradigm and some of by clicking events of an application are
considered in event-driven paradigm in code structure and lastly some code part is written in modules
using functions and encapsulated with a single class which also referred as a part of programming
paradigm implementation which matches the characteristics of programming paradigms.
8
Document Page
LO3
P3
Programs
Figure 1 Problem 1.1
9

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
Figure 2Problem 1.2
Figure 3Problem 1.3
10
Document Page
Figure 4Problem 1.4
Figure 5 Problem 1.5
11
Document Page
Figure 6 Problem 1.6
12

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Figure 7Problem 1.7
Figure 8 Problem 1.8
13
Document Page
Figure 9 Problem 1.9
Results
Figure 10Solution 1.1
14
Document Page
Figure 11Solution 1.2
Figure 12Solution 1.3
15

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
Figure 13Solution 1.4
16
Document Page
Figure 14Solution 1.5
Figure 15Solution 1.6
17
Document Page
Figure 16Solution 1.7
18

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Figure 17Solution 1.8
19
Document Page
Figure 18Solution 1.9
Figure 19MENU
20
Document Page
M3
Demonstrating IDE
In this figure, this IDLE showing how to open a file, module, path and class browser and some saving
options to execute the .py file using this IDLE.
Figure 20IDLE
21

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
In this figure, showing edit menu in which some components of edit are shown which is used for
execution of program file in this IDLE.
Figure 21IDLE
22
Document Page
Figure 22About IDLE
23
Document Page
Figure 23Debug IDLE
D3
Cons ofusing an IDE:
• IDE may not be a decent mechanism for starting software engineers.
24

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
• The expectation to absorb information in IDEs is confounded tool. Augmenting their advantage will
require.
• Time and tolerance.
• It won't settle awful code, practices, or outline, for example, IDE won't kill productivity or execution
issues in your application.
• IDE utilizes graphical interface which requires more memory and handling power.
•Some IDEs don't enable users to collaborate with the database straightforwardly.
Pros for use an IDE:
The software is smaller(about 16M)
It is simple to learn with IDLE because it does not have many packages to know
It has a standard library
Keeping a perspective of records, mistakes/notices/reassure/unit tests and so on and source
code all on the screen in the meantime conveniently.
Ease of running unit tests from a similar window.
It comprises of coordinated investigating.
It has coordinated source control.
Navigating to where an order time blunder or run-time special case happened specifically
from the mistake points of interest.
25
Document Page
LO4
P4
Debugging
Troubleshooting, in PC programming and designing, is a multistep procedure that includes
distinguishing an issue, confining the wellspring of the issue, and after that either redressing the issue
or deciding a procedure to work around it. The last advance of troubleshooting is to test the revision
and ensure it is right. Troubleshooting is a piece of the product testing process and is a fundamental
piece of the whole programming improvement lifecycle.
To decide the mistake or bugs in code and to settle this blunder, utilize the "breakpoint" and run the
program until that breakpoint, at which time program execution stops. The investigating part of an
IDE commonly furnishes the developer with the ability to see memory and see factors, run the
program to the following breakpoint, execute only the following line of code, and, now and again,
change the estimation of factors or even change the substance of the line of code going to be executed.
IDLE has a debugger incorporated with it. It is exceptionally helpful for venturing through a program
and viewing the factors change esteems.
Start python IDLE and open or create new program to rectifybugs just like an example shown below.
26
Document Page
Figure 24Program file to debug
Now in the Shell window of idle, tap on the Debug menu option show in menu bar at the top and then
on Debugger option and later on there’s a debug control option.
27

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
Figure 25Program file to debug
On this, you notice that the DEBUG ON is shown in this picture which represents debugging process
is undergoing this phase.
Debug Control Menu
28
Document Page
• Over implies that if the announcement to be executed as a function call bring in it, go off and do the
function call without demonstrating any subtle elements of the execution or factors, at that point
return and give the human control once more, "step over the capacity"
•Out accept you are in some function code, complete execution of the function at ordinary speed,
come back from the capacity and after that give the human control once more, "advance out of the
capacity"
•Quit stops the execution of the whole program
Presently set a breakpoint in your source code before you begin running the program. A breakpoint is
a marker on your code that tells the debugger "hurried to this point at typical speed, at that point delay
and let the user have control". Right-tap on a line of your source and pick "set breakpoint" which is
appeared in underneath the picture.
Figure 26Setting Breakpoints
After this, the background of the line you clicked willchange in yellow colour which shows the code
sentence marked with the breakpoint, and can check in upcoming image and can remove breakpoint
after correcting or changing the errors/bugs.
29
Document Page
Figure 27After breakpoint, the line turns yellow
Starting here, you can tap the Go button close to the highest point of the window. This will influence
the program to keep running at typical speed until a breakpoint is experienced. You can likewise
utilize the Step button to step through your code, one line at any given moment. This button is utilized
a considerable amount. On the off button that the line being stepped through has a function call,
execution will go to the main line of the function definition (you are "stepping into" the capacity). In
the event that the line being stepped through doesn't have a function call, the line is executed. In either
case, at that point control backpedals to the user.
30

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Figure 28 Control window of debugging
From this debugging process, you can debug the errors and check again to get the output of your
program.
So the process of using the debugger involves
Setting breakpoints,
Stepping through the source code one line at any given moment,
Inspecting the estimations of factors as they change,
Making remedies to the source as bugs are found,
Rerunning the program to ensure the fixes are right.
P5
b) Code Standards
31
Document Page
Coding standards are some conditions which aremostly used in programming to fulfill the
developer requirements and shows sincerity in programs. Coding standards are set of
guidelines, styles of programming and conventions are followed when writing source code.
To make every bite of code look and feel familiar, we used some coding standards, some
points are as follows:
1. We’re not starting identifiers with Underscore(_)
2. In this code, all single letters written in lowercase
3. Not giving space in identifiers but using capitalization of the word.
4. We’re using capital letters to define or declare constants
5. All functions names start with a capital letter
6. Using relative identifier and function name with the problem given.
M4
By debugging process, it’ll help to produce more secure and robust applications by removing errors
and bugs. These applications are more flexible, simplified in use by everyone in real life which
prevents from daily complaints and give good reviews. Debugging is a part of programming which is
related to software testing used for providingan error-free application for use by clients or customers.
Debugging helps to discover memory issues and executions problems on different devices which
helps in deploying the application.
While debugging, get alerts when things are going wrong and after debugging the program you can
rectify before deploy that will not affect your application and not create problems for the user that’s
why debugging is commonly a part of programming and helps in provide more secure and robust
applications.
D4
Coding standards are necessary to follow by an individual or in a team because it fulfills the
guidelines of programming language and give the best understanding to the user which helps in to
process easily on code or anything.Coding standard enhances the nature of the general programming
framework. The way to a decent coding standard is consistency. This consistency should be found
inside the standard itself yet in addition inside the source code that uses the standard. Finished source
code ought to mirror a fit style as though a solitary designer or group composed the code in one
session.
32
Document Page
The accompanying reasons are there for utilizing coding norms by an individual or in a group as:
1. Security Issues: The fundamental explanations behind regularly misused programming
vulnerabilities are irregularities, bugs, and blunders in the rationale. The greater part of these issues
emerge because of programming blunders that outcome from poor coding rehearses.
2. Site Performance Issues: Bad coding influences the general execution of the site. Different
execution issues incorporate User Interaction, Server Response, Code reusability, Flow issues, and so
on.
33

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
CONCLUSION
This report concludes that all the modules are done by following programming paradigms and
debugging process which helps to prevent errors and coding standards also applying to understand
and provide a better look for viewers.It follows all oops concept related to programming and
procedural programming which defines basic tools for execution. The source codes are secure as well
as robust which give the best results and describes algorithm with understanding language for the
user. At last, all programs encapsulated in functions under menu give the best result and fulfill all
requirements of programs.
34
Document Page
REFERENCES
Cs.uky.edu. (2018). [online] Available at: https://www.cs.uky.edu/~keen/help/debug-
tutorial/debug.html [Accessed 25 Apr. 2018].
Degruyter. (2018). [online] Available at:
https://www.degruyter.com/downloadpdf/j/cris.2013.2013.issue-2/cris-2013-0011/
cris-2013-0011.pdf [Accessed 25 Apr. 2018].
Drupal. (2018). Coding standards. [online] Available at:
https://www.drupal.org/docs/develop/standards/coding-standards [Accessed 25 Apr.
2018].
Idlex.sourceforge. (2018). IdleX - IDLE Extensions for Python. [online] Available at:
http://idlex.sourceforge.net/features.html [Accessed 25 Apr. 2018].
Techopedia.(2018). What is Procedural Programming? - Definition from Techopedia.
[online] Available at: https://www.techopedia.com/definition/21481/procedural-
programming [Accessed 25 Apr. 2018].
Veracode. (2018). What Is an Integrated Development Environment (IDE)?. [online]
Available at: https://www.veracode.com/security/integrated-development-
environments [Accessed 25 Apr. 2018].
35
1 out of 36
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]