Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Chapter 1_python

Chapter 1 introduces programming concepts, including problem-solving steps, definitions of computer programs and coding, and distinctions between programming and scripting. It outlines programming paradigms, the roles of compilers and interpreters, and the features of the Python programming language. Additionally, it discusses the use of Python in real-world applications and provides insights into tools like Python IDLE and the command line interface.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Chapter 1_python

Chapter 1 introduces programming concepts, including problem-solving steps, definitions of computer programs and coding, and distinctions between programming and scripting. It outlines programming paradigms, the roles of compilers and interpreters, and the features of the Python programming language. Additionally, it discusses the use of Python in real-world applications and provides insights into tools like Python IDLE and the command line interface.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Chapter 1 Introduction to Programming

Chapter 1 – Manual

Introduction to Programming
Conceptual Questions

1. List the steps involved in solving a problem.

Answer The steps involved in solving a problem are as follows: gaining insight into the problem
at hand; conducting in-depth analysis; designing and developing a workable solution;
drafting and testing the necessary code; and finally, releasing the solution to the world.

2. Define a computer program.

Answer The definition of a computer program is a comprehensive and step-by-step set of


instructions that tell a computer exactly what it should be doing.

3. What is coding? Explain the coding mechanism.

Answer Coding, a subset of computer programming, allows humans to exchange information


with machines. Coding is used to enable Computers to understand the human levels of
linguistic comprehension. The term "coding" refers to the language used to instruct a
computer on how to carry out a specific task. It is the medium by which humans convey
their ideas and intentions to computers as instructions. These instructions dictate to the
computer how to define and complete a task (on what to do) in a way (how to do it) that
it can understand.
Coding Mechanism-Coding guarantees that a computer's software and hardware can
communicate by compiling the code into assembly language. High-level and assembly-
level languages are converted into Binary Coded Signals (ones and zeros) during coding
to allow computational hardware and software to communicate.

COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD


4. Outline the notion of “Programming” and explain the Programming Mechanism

Answer “Programming” means providing the computer with the data and instructions
necessary to carry out the desired task. Programming is what makes it possible for
computers to carry out specific tasks. C, C++, Java, Python, etc., are just a few of the
many programming languages out there that foster innovation and originality in the tech
industry.
Programming Mechanism-The process of programming is complicated. In contrast to
coding, programming is done in phases, or "Stages," like Problem Statements, drawing
Flowcharts and Coding Algorithms, Crafting Computer Programs, Analyzing and
Evaluating Software, Technical Writing About Computer Programs, Upkeep of
software, and so on.

5. Compare and contrast programming and scripting.

Answer PROGRAM SCRIPTING


Is executed Is interpreted
The sequence of instructions written A code written in a scripting language is
so that a computer can perform a called “script” and is a programming
specific task is called a program. language in which we can write code to
control another software application.

6. List out the design paradigms in a programming language.

Answer The term “programming paradigm” refers to a specific way of approaching the solution
of a problem in any given programming language. The term “paradigm” refers to a
pattern or model, whereas “paradigm in programming” refers to a model that solves a
problem. The paradigm is the guiding principle that all computer science programming
languages should adhere to when attempting to solve a problem. There are three
essential programming paradigms in this computer era: Object Oriented Programming

COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD


Chapter 1 Introduction to Programming

(OOP), Functional Programming, and Procedural Programming. In specific


applications, other application specific paradigms are preferred.

Object Oriented Programming (OOP) is based on the objects which contain the data as
variables and perform activities using the associated methods. Functional Programming
involves creating programs by constructing and applying functions in which functions
are the trees of expressions that map the values to other values. Procedural
Programming
involves programs that consist of data and procedures that operate on the data. Critical
differences between OOP, Functional Programming, and Procedural Programming are
listed in Table 1.1.
Hint:
Table 1.1. Object Oriented Programming Vs. Procedural Programming Vs. Functional
Programming.

7. With the pyramid illustration, show and explain the various levels of the
translation of languages.

Answer Fortran, C, Pascal

High Level Language

Assembly Language

Machine Languagee

Hardware

Figure. 1.1: Pyramid Showing the Level of the Translation of Languages


Hint:
1.2 Programming Versus Software

8. List the characteristics of the Python Programming Language.

COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD


Answer Hint:
1.3. Characteristics of Python Programming Language

9. What is scripting?

Answer "Scripting" is a vague phrase. Scripting is a complex and vital programming discipline,
but its lexicon is alienating. Scripting is used to do repeated activities on computers.
Scripting is writing code that performs a real-world activity without compiling.
Scripting may be done on many systems via the command line and various computer
languages. Scripting may be done in a wide range of contexts across a wide range of
settings, including servers, operating systems, applications, games, websites, and
software, as well as other languages and the command line.

10. List the shortcomings of using Python.

Answer Hint:
1.3.1.
 Speed is an issue. Since it is an interpreted language, it is several times slower
than compiled languages.
 Design restrictions. The dynamically typed language comes with errors only at
runtime; Python’s global interpreter lock and whitespace are a few design issues.

11. What are compilers, and how do you explain them? Give an example.

Answer A Compiler reads the program and translates it fully before the program starts running
FEATURE COMPILER
Input Scans and takes an entire program simultaneously and
translates it into a machine code.
saving Saves code as it compiles it
Output It creates intermediate object code.

COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD


Chapter 1 Introduction to Programming

Working The compilation is done before execution.


mechanism
Speed Comparatively faster. It takes more time to examine the source
code, but the execution time is reasonably faster.
Memory Requires more memory due to the creation of object code.

Errors Exhibits all errors after compilation, all at the same time.
Error Difficult
detection
Pertaining C, C++, C#, Scala, and typescript uses a compiler.
Programming
languages

12. What is an interpreter? Provide an example.

Answer An interpreter, takes a single line of code or instruction at a time and translates it.
Doesn’t save the interpreted code. It does not create any intermediate output object
code. Compilation and execution take place concurrently. It is slower. It takes less
amount of time to examine the source code but the overall execution time is slower. It
requires less memory as it does not generate intermediate object code. Exhibits error of
each line one by one. Easy Error detection. Example: PHP, Perl, Python, Ruby uses an
interpreter.

13. What features of an interpreter does a compiler also have? What makes them
unique from one another?

Answer BASIS FOR COMPILER INTERPRETER


COMPARISON
Input Scans and takes an entire It takes a single line of code
program at a time and or instruction at a time and
COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD
translates it into a machine translates it.
code.
saving Saves code as it compiles it Doesn’t save the interpreted
code
Output It creates intermediate It does not create any
object code. intermediate object code.
Working The compilation is done Compilation and execution
mechanism prior to execution. take place concurrently.
Speed Comparatively faster. It Slower. It takes less amount
takes more time to examine of time to examine the
the source code but the source code but the overall
overall execution time is execution time is slower.
reasonably faster
Memory Requires more memory It requires less memory as it
due to the creation of does not generate
object code. intermediate object code.
Errors Exhibits all errors after Exhibits error of each line
compilation, all at the same one by one.
time.
Error detection Difficult Easier comparatively
Pertaining C, C++, C#, Scala, PHP, Perl, Python, Ruby
Programming typescript uses compiler. uses an interpreter.
languages

14. What are the critical differences between compiled code and interpreted code?

Answer Interpreters and Compilers are two kinds of programs which process high-level
languages into low-level languages.
A Compiler reads the program and translates it fully before the program starts running.
In this perspective, the high-level program is called the source code, and the translated

COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD


Chapter 1 Introduction to Programming

program is called the object code or the executable. After a program is compiled, you
can execute it repeatedly without further translation.
The compiled object code can be run by a hardware executor.
An interpreter, takes a single line of code or instruction at a time and translates it.

15. What tool does a computer programmer use to create Python source code?

Answer Python offers tools for the system, graphical user interfaces, persistent storage, database
management systems, and so on.

16. What are the prerequisites for putting a Python program into action?

Answer Python interpreter reads the expression or statement (source code), and confirms that
it is well formed. In this step, the interpreter acts like a strict guard, who, rejects any
person gaining entry to any premise or syntax (sentence) that does not adhere to the
grammar rules, or syntax, of the language. As soon as the interpreter encounters such
an error, it halts translation with an error message.
If a written Python expression is well formed, the interpreter then translates it to an
equivalent form in a low-level language called byte code. When the interpreter runs a
script, it completely translates it to byte code, which is sent to another software
component, called the Python virtual machine (PVM), where it is executed.

17. Give some examples of how Python is used daily.

Answer  Console Based Applications like IPython.


 Audio or Video based Applications TimPlayer, cplay are some of the
applications in multimedia section.
 3D CAD Applications-Fandango is a real application which provides full
features of CAD.
 Web Applications like PythonWikiEngines, Pocoo, Python Blog Software
 Enterprise Applications- are used to create applications which can be used
COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD
within an Enterprise or an Organization. Some real time applications are: Open
ERP, Tryton, Picalo etc.,
Applications for Images image Applications developed are: VPython, Gogh, imgSeek
etc.,

18. Enumerate the benefits of working with the Python programming language.

Answer unique features viz.


 Dynamic
 Extensible in C++ & C
 High level
 Interactive
 Interpreted
 Modular
 Object-oriented
 Portable

19. Describe what the command line interpreter is.

Answer Refer to section for 1.5.3. Command Line Interpreter

20. Write notes concerning the Integrated Development and Learning Environment
(IDLE).

Answer Refer to section for 1.6. Python IDLE Editor

21. List the features of Python IDLE.

Answer Python IDLE's features are as follows:


 Compatible across multiple operating systems.
 Created entirely using Python's tkinter GUI library.

COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD


Chapter 1 Introduction to Programming

 An interactive Python shell window with colourized input, output, and error
messages.
 Python-friendly multi-window text editor with call tips, auto-completion, and
code colouring.
 Replaces text in multiple editor windows, syntax highlighting, smart indenting,
call stack conspicuousness, auto-completion search across multiple files, and
search any window (grep).
 A debugger with persistent breakpoints, step-through code, and
namespace(global and local) inspection.
 Various menus for setting up and browsing the internet.

22. How to select a code editor for Python that can meet the requirements?

Answer Refer to section for 1.6. Python IDLE Editor

23. If someone needs assistance with Python, where can they go and how can they get
it?

Answer Python interpreter helps. For example, if you want to know how an object works, you
must call for help(<object>)! .
The most up-to-date and current source code, binaries, documentation, news, etc. is
available at the official website of Python:
Python Official Website: https://www.Python.org/
You can download the latest version of Python one can visit
https://www.python.org/downloads/.
Python's documentation, tutorials, and guides can be browsed or downloaded from the
following site.
Python Documentation Website: https://www.Python.org/doc/

24. Write the standard Python syntax colours for keywords, strings, comments, and

COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD


definitions.

Answer Common Python syntax colors:


Keywords in orange color
Strings in green color
Comments in red color
Definitions in blue color
Misc. Words in black color

25. Why utilize the command line if a computer can be handled using intuitive
software and a Graphical User Interface (GUI)?

Answer It has three leading causes.


 The ability to automate instructions is a huge plus for this system. One example
is a script that always shuts off services or programs when a user logs in. Other
tools may be used to copy files of the same type from a folder without manually
filtering through the contents. Using commands, these chores may be completed
swiftly and efficiently.
 Direct access to the operating system's capabilities is another benefit of using a
CLI. The simplified and robust access it offers to advanced users may appeal
to them.
 Command line interfaces are not as user-friendly as graphical programs. Thus,
primary and inexperienced users shun them.

26. How can the CMD (Command Prompt) compile and run a Python program?

Answer Refer to section for 1.5

27. What is Python virtual machine (PVM)?

Answer PyVm is a free programming environment for the Python programming language. Bytes

COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD


Chapter 1 Introduction to Programming

are translated into machine instructions that the computer can execute and display.

TRY OUT QUESTIONS

1. Develop your capacity to tackle complex problems by applying your knowledge to


actual situations. Use programming language features to foster creative problem-solving
skills and encourage logical reasoning.

2. Pick the right programming paradigm to apply to some real-world issues.

3. Why is the Future of Python Language Bright?


https://www.probytes.net/blog/python-future/

4. Why Python uses 0-based indexing?


http://python-history.blogspot.com/

5. The Only Way To Learn Programming


https://renanmf.com/the-only-way-to-learn-programming/

PROGRAMMING EXERCISES

1. Investigate how Google employs Python.

COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD


Hints:
a. Use for maintenance and delivery.
b. To rewrite Google's Perl and Bash scripts as it is easy to deploy and
maintain. Google's first web-crawling spider was rewritten in Python.
c. Python is one of Google's four production-ready server-side languages,
along with C++, Java, and Go.

2. Explore Spotify Python usage and why they chose to use it.

Hints:
a. For data analysis
b. For Back-end inter-service communication -. ZeroMQ, an open-source
networking library and framework, is written in Python
c. For its fast development.
d. Spotify's infrastructure implemented with Gevent -fast event loop and high-
level synchronous API have been used to implement Spotify's recent
infrastructure changes.

3. Find out how Uber is benefiting from Python.

Hints:
a. Uber's core platform runs on Python, Node.js, Java, and Go. Python powers
many user services with estimations and business logic.
b. Arrival times, route planning, region research, and supply-demand balance
require higher-order thinking.

4. Learn how Python is used on the Amazon platform.

Hints:
 Amazon's analysis and recommendation system use AI and ML to find what

COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD


Chapter 1 Introduction to Programming

customers want.
 Python's scalability and compatibility with Hadoop made it ideal for
Amazon's data processing needs.
 Amazon uses Python for a wide variety of purposes, such as Machine
Learning and automating AWS resources, and one way it does this is with
Jupyter notebooks.

5. Look into how the Dropbox desktop client uses the Python programming
language for cloud based storage.

MULTIPLE CHOICE QUESTIONS

Listed below are statements and questions. The statement or question will be followed by
four possible answers. Select the option that completes the statement or answers the
question.

1. Which version of Python is the most recent one that can be downloaded and
utilised?

a. Python 3.13
b. Python 3.10
c. Python 3.12
d. Python 3.11

Answer d. Python 3.11

2. In the world of Python, IDLE is an abbreviation that stands for:

a. Integrated Design and Learning Environment


COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD
b. Integrated Development and Learning Environment
c. Integrated Development and Linear Environment
d. International Development and Learning Environment

Answer b. Integrated Development and Learning Environment

3. If Python is already installed on your Operating System, it is called by its


name.

a. Easy Python
b. Monty Python
c. Onboard Python
d. System Python

Answer b. Monty Python

4. Who is attributed with the development of Python Programming Language?

a. Wick van Rossum


b. Niene van Stom
c. Rasmus van Lerdorf
d. Guido van Rossum

Answer d. Guido van Rossum

5. What other programming languages can be used in conjunction with the


Python language?

a. object-oriented programming
b. structured programming
c. functional programming
d. all of the above mentioned
COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD
Chapter 1 Introduction to Programming

Answer d. all of the above mentioned

6. Which of the following is the correct file extension for the Python program?

a. .python
b. .pl
c. .py
d. .p

Answer c. .py

7. What is the name of a Python file that ends in ".py"?

a. package
b. module
c. directory
d. namespace

Answer b. module

8. Which year is regarded as Python's inaugural year?

a. 1972
b. 1995
c. 1989
d. 1981

Answer c. 1989

COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD


9. Python is written in what language?

a. C
b. C++
c. Java
d. C#

Answer a. C

10. Which function can help us find our current Python version?

a. sys. version(1)
b. sys. version(0)
c. sys. version(2)
d. sys. version

Answer a. sys. version(1)

11. Code written in Python is compiled or interpreted?

a. Python code is both compiled and interpreted


b. Python code is neither compiled nor interpreted
c. Python code is only compiled
d. Python code is only interpreted

Answer b. Python code is neither compiled nor interpreted

12. The programming language Python is at the __ level.

a. Low level
b. Medium Level
c. High Level
COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD
Chapter 1 Introduction to Programming

d. None

Answer c. High Level

13. When was the first version of python released?

a. 2001
b. 1991
c. 1981
d. 1995

Answer b. 1991

14. Python shell is fundamentally a

a. Python compiler
b. Python developer
c. Python interpreter
d. Python debugger

Answer c. Python interpreter

15. In which mode can Python write and save

a. Script mode
b. Interactive mode
c. Command line argument
d. None of the above

Answer a. Script mode

COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD


16. What is the command which helps to create recursive folders, which fill in
missing parent folders of leaf folders

a. os.ckdir('new-dir')
b. os.mhdir('new-dir')
c. os.chdir('new-dir')
d. os.mkdir('new-dir')

Answer d. os.mkdir('new-dir')

17. What is the command that helps to get the file system representation of a
path

a. os.fgpath(*path)
b. os.fscath(*path)
c. os.fspath(*path)
d. os.fspat(*path)

Answer c. os.fspath(*path)

18. What is the command that helps change the mode of a file descriptor to
numeric

a. os.fahmod(*fd, mode)
b. os.fchmod(*fd, mode)
c. os.fchmod(*fd, mode)
d. os.fshmod(*fd, mode)

Answer c. os.fchmod(*fd, mode)

19. Name the command which helps the Python os module to close the
COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD
Chapter 1 Introduction to Programming

associated file with descriptor fd.

a. os.clse(fd)
b. os.close(fd)
c. os.halt(fd)
d. os.hat(fd)

Answer b. os.close(fd)

20. Name the command that lets to delete the directory path.

a. rmdir(path)
b. deldir(path)
c. rmldir(path)
d. rmedir(path)

Answer a. rmdir(path)

21. Name the command that launches the interpreter in a command prompt

a. import cs
b. import operating system
c. import os
d. import ls

Answer c. import os

22. CLI is better than GUI as it is

a. Faster and more efficient


b. gives the user additional control

COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD


c. relatively fast while switching between icons.
d. All of the above

Answer d. All of the above

23. People who are fluent in the language known as ------------------

a. Praselmoths
b. Praslmouths
c. Praselmouths
d. Praselmouts

Answer b. Praslmouths

24. Name the command to rename a file or directory. If the destination is a file
or a directory that already exists, it raises an OSError.

a. renamed()
b. renaming()
c. reneme()
d. rename()

Answer d. rename()

25. Name the command that lets to change the working directory

a. chdir(path)
b. ckdir(path)
c. chdi(path)
d. chdr(path)

Answer a. chdir(path)
COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD
Chapter 1 Introduction to Programming

26. This command displays the system platform, the machine architecture,
release, and version information. getcwd function returns the current
working location of the directory.

a. os.getcwd()
b. os.gotcwd()
c. os.getcvd()
d. os.getewd()

Answer a. os.getcwd()

27. Name the command that returns a unique path name reasonable enough to
create a temporary file.

a. tempnam([dir[, prefix]])
b. tempvam([dir[, prefix]])
c. tempmam([dir[, prefix]])
d. tempnan([dir[, prefix]])

Answer a. tempnam([dir[, prefix]])

28. Name the command that returns the names of directory entries at the path.

a. listdir(path)
b. lictdir(path)
c. listder(path)
d. listdier(path)

Answer a. listdir(path)

COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD


COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD

You might also like