Chapter 1_python
Chapter 1_python
Chapter 1 – Manual
Introduction to Programming
Conceptual Questions
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.
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.
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
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.
Assembly Language
Machine Languagee
Hardware
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.
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.
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
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?
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
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.
18. Enumerate the benefits of working with the Python programming language.
20. Write notes concerning the Integrated Development and Learning Environment
(IDLE).
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?
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
25. Why utilize the command line if a computer can be handled using intuitive
software and a Graphical User Interface (GUI)?
26. How can the CMD (Command Prompt) compile and run a Python program?
Answer PyVm is a free programming environment for the Python programming language. Bytes
are translated into machine instructions that the computer can execute and display.
PROGRAMMING EXERCISES
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.
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.
Hints:
Amazon's analysis and recommendation system use AI and ML to find what
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.
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
a. Easy Python
b. Monty Python
c. Onboard Python
d. System Python
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
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
a. package
b. module
c. directory
d. namespace
Answer b. module
a. 1972
b. 1995
c. 1989
d. 1981
Answer c. 1989
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
a. Low level
b. Medium Level
c. High Level
COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD
Chapter 1 Introduction to Programming
d. None
a. 2001
b. 1991
c. 1981
d. 1995
Answer b. 1991
a. Python compiler
b. Python developer
c. Python interpreter
d. Python debugger
a. Script mode
b. Interactive mode
c. Command line argument
d. None of the above
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)
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
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
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]])
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)