To
My dear sister Kesari Verma
PREFACE
Who is this book meant for?
Even though Python programming is easy, it does require certain preparation in mathematics and logic. Therefore, I believe that students of classes X to XII will enjoy this book. However, younger students too could attempt to study parts of the book.
Some topics of the book are somewhat difficult. Still, I recommend that the students should learn them by spending more time. If you find some chapters or sections (e.g., prime numbers) to be too difficult, you could skip them and move on. Part-II of the book deals with Algebra, geometry, and a bit of statistics. This optional part may interest mathematics students of class XI and XII.
How to use this book?
Programming is like painting or swimming. We learn these skills by practice. Hence, I strongly urge the students to practice coding, rather than simply reading the book. Open your computer and type the statements of the book and run the codes. Do as many exercises as possible! For your convenience, the codes of the book, as well as video lectures and PPTs, will be made available on the website https://sites.google.com/view/py-school. We plan to offer a Python course for school students on Prutor (https://prutor.ai/mkvatiitkanpur/#)
Acknowledgements
First, thanks to Python developers for creating wonderful programming environment, that too for free! I am grateful to Anancoda for the free Python distribution. This book was created effortlessly using Scrivener.
This book is a simpler version of my Computational Physics course at IIT Kanpur. I am grateful to the course TAs (teaching assistants), especially Soumyadeep Chatterjee, Abhishek Kumar, Manohar Sharma, and the class students for suggestions and comments.
I am also thankful to my sister Late Kesari Verma, Rahul Garg, Prachi Garg, and Shalini Tiwari for the encouragement to complete this project; and to Ishika Sinha, Vikas Gupta, and Dhruv Garg for a careful proofread of the book. Finally, special thanks to Nitin Soni and his publication team at Adhyyan Books for the assistance in publication of this book.
I gratefully acknowledge Wikipedia and Wikieducator for Figures 2, 4, 5, 35, and 55 of the book.
Feedback request
I request the readers to send their comments and feedback to me at . Even though I have tried hard to make the book error free, I am sure some bugs still remain. I will be grateful if the errors are brought to my attention.
Mahendra Verma
General Introduction to Computers
The digital revolution is far more significant than the invention of writing or even of printing. Douglas Engelbart
CHAPTER ONE
Introduction to Computers
I do not fear computers. I fear lack of them.
Isaac Asimov
Computers are everywhere and they impact all walks of lives. This chapter gives a brief introduction to computer hardware and software.
COMPUTER HARDWARE
A COMPUTER IS a digital device that stores and processes data, typically digital data. In addition, a computer can be programmed to perform different tasksweb browsing, email, running programs, playing music and movies, controlling a car, etc.
Let us illustrate the functioning of a computer using an example. We want to build a pizza cutter that cuts a pizza into required number of pieces. This machine has several important features:
- Input: Full-size pizza and the number of required pieces.
- Storage: Here we place a full-size pizza that is to be cut into smaller pieces.
- Output: Dispenser for the pizza pieces.
- Processor: This unit cuts the pizza to smaller pieces.
A schematic diagram of the machine is illustrated in Figure 1. The working of the above machine is as follows:
- Insert the pizza, and input the number of required pieces.
- Cut the full pizza into the required number of pieces.
- Dispense the cut pieces.
Figure 1: A pizza cutter takes a full-size pizza, cuts it into the required number of pieces, and delivers them.
We could iterate this process to cut more pizzas. The above pizza cutter is programmable because we can change the required number of pieces. Vending machine too is a programmable device. However, a hammer or a knife is not a programmable device; these machines can do only one thing.
After this simple example, we briefly describe a computer. At present, most people use laptops, hence we will detail this device. You have seen a desktop computer or a laptop. Other kinds of computers will be mentioned at the end of the section. In the following discussion, we will describe a laptop in some detail.
Exterior of a laptop
The exterior of a laptop has a screen, a keyboard, a trackpad, a camera, and several ports. The ports are typically on the sides of the laptop. See Figure 2 for an illustration. Let us describe the above parts briefly:
Figure 2: (a) Laptop; (b,c) Ports of a laptop. Adapted from figures of wikipedia.org . Source: Wikipedia.
Keyboard : A computer takes inputs or commands from a user via a keyboard. A computer program is also entered in the laptop using the keyboard.
Screen : The computer displays its output on the screen, which is also called a display monitor . The output could be text, images, or videos coming from a computer program, an internet, or a keyboard. A screen could exhibit multiple outputs on different windows. For example, your could read your email, browse the internet, and watch a movie in three different windows on the monitor.
Trackpad : Trackpad is an input device of a laptop. We can reach various parts of a screen using a trackpad.
Camera: We can either take a picture or record a video using the laptops camera. Note that the image or video of the camera could be an input to a program, e.g., Whatsapp or a video-editing program.
Power port: The port is for charging the battery located inside the laptop.
USB port : Using a universal serial bus ( USB ) port, we can either copy data from a pendrive to a laptop or transfer data from a laptop to a pendrive. In addition, cameras, scanners, and printers can be connected to the laptop using a USB port.
Audio in/out : We can hear music or record music by inserting an audio cable to the Audio in/out port of the laptop.
Firewire and Thunderbolt ports : These ports are useful for connecting the laptop to external display devices, such as a TV or a projector.
Ethernet port : A laptop can receive/send data from/to an internet via an ethernet cable attached to an ethernet port. However, most modern laptops do not have ethernet port and they use only a wireless connection for internet data transmission. The wireless device resides inside a laptop.
Some of the recent laptops avoid multiple ports mentioned above. Instead, they have several USB-C ports (see Figure 2(c)) that is used for charging the laptop, as well as for connecting to a USC-C hub. The USB-C hub has many ports for connecting to pendrive, external monitors, TV, projector, ethernet, etc.
The laptop connects to the outside world using these input/output components (keyboard, monitor, touchpad, cameras) and ports. This is similar to how an animal interacts with the outside world using eyes, ears, mouth, nose, etc. Clearly, the input data goes inside the laptop. What does a laptop do with this data? To answer this question, we need to get inside the laptop.