GOOGLE ANDROID
Android is an operating system for mobile computing devices. Android is
created and maintained by Google. It is widely used on smartphones and
tablet computers. Various hardware manufacturers like Asus, Dell, HP, HTC,
LG, Motorola, Samsung, and Sony use Android as the operating system for
their devices. It provides a wide range of features, from sending e-mail
and browsing the Internet to making phone calls and taking photos.
Google has released many versions of the Android operating system. Each version had a code
name from a sweet food and in alphabetical order till now but the latest version doesn’t follow
this format.
For example, the code name for Android versions 1.5 is Cupcake, 1.6 is Donut, 2.0 to 2.1 is Eclair,
2.2 is Froyo, 2.3 is Gingerbread, 3.0 to 3.2 is Honeycomb, 4.0 is Ice Cream Sandwich, 4.1 to 4.3 is
Jelly Bean, 4.4 is KitKat, 5 is Lollipop, 6 is Marshmallow, 7.1 is Nougat, 8.0 is Oreo, 9.0 is pie and
version 10 is Android 10.
Google Devices
GOOGLE PIXEL
Google Pixel is an Android smartphone designed and marketed by
Google. It includes all your favorite Google apps to bring you a fast,
seamless, and easy-to-use experience. Similar to Nexus devices, it
receives Android updates directly from Google.
All Pixel smartphones include very large storage for all your photos and
videos. Pixel is the first phone with the ‘Google Assistant’ built in.
PMP
GOOGLE GLASS
IT PLANET - 8 (UBUNTU 18.04)
Google Glass is a wearable, voice-controlled Android
device which looks like a pair of eyeglasses. It
enables the user to view information or take photos
and videos that are projected to a miniature screen
in the user’s field of vision. Users control the device
through voice commands or by touching controls on
its frame.
GOOGLE HOME 101
Google Home is a voice-activated smart speakers developed by
Google. Google Home speakers enable users to speak voice
commands to interact with services through Google Assistant.
Google Home can play music, news, perform home automation tasks
and answer complicated questions.
Self-Evaluation CHECKLIST
PM PUBLISHERS PVT. LTD.After reading the chapter, I know these points:
$ I know that Google is an American public corporation, specializing in Internet-related
PMP
Agreeservices and products.
Disagree
$ I know that Google has developed a number of web-based applications that are
collectively known as Google Apps.
$ I know that Google Apps are totally based on cloud computing which means storing
and accessing data and programs over the Internet.
$ I fully know that Google Docs is an online Office Suite, in which you can create, edit
and share three types of documents.
$ I know that Google Maps enables you to display up-to-date maps by searching for
an address or place of interest.
$ I know that Android is an operating system for mobile computing devices. It is
created and maintained by Google.
$ I know that Google Glass is a wearable, voice-controlled Android device which looks
like a pair of eyeglasses.
Exercises
A. Tick [ü] the correct answer.
102
1. Google Apps are totally based on ............................. for storing and accessing data and
programs over the Internet.
a. Cloud Computing b. Soft Computing c. Hard Computing
2. Google Chrome is a full-featured ......................... software designed by Google.
a. Web Server b. Web Browser c. Web Page
3. ......................... is a free online language translation service which instantly translates text
into other languages.
a. Google Writer b. Google Reader c. Google Translate
4. ............................. is store for apps, songs, books, movies, games and other contents for
Android-powered phones and tablets.
a. Google Play b. Google Allo c. Google Docs
5. Google ......................... is a blog-publishing service by Google by which you can publish your
ideas, opinions and stories online.
a. Writer b. Blogger c. Docs
6. ......................... offers tens of millions of videos as well as movie trailers, commercials, clips
from TV shows and much more.
a. YouTube b. Google Drive c. Google Assistant
7. ......................... is an interactive mapping program that covers the vast area of the Earth.
a. Google Pixel b. Google Glass c. Google Earth
B. Write ‘T’ for True and ‘F’ for False statements.
1. To gain access to all the Google services, you must set up a Gmail account.
2. Google Drive is used to determine the current location of a user.
3. The Google Translate app for mobile lets you instantly visually translate printed
text.
4. Each version of Android operating system has a code name from a sweet food
and in alphabetical order.
5. Google glass is a high quality video calling app.
6. In Google Home, photos and videos always have to be backed up and organized
manually.
C. Fill in the blanks.
1. Google was founded by .......................................... and .......................................... .
2. ............................. is the product of Google Apps, which is used to send and receive e-mails.
3. .................................... is an online storage that provides 15 GB of free Google storage.
4. .................................... is a time management app developed by Google.
5. ........................................... is Google’s communication app that allows you to communicate
instantly using instant messaging, video or voice chat and SMS anywhere in the world.
PMP
6. .................................... is a voice activated smart speakers.
D. Differentiate between the following.
1. Traditional Computing Cloud Computing
................................................................. .................................................................
................................................................. .................................................................
................................................................. .................................................................
2. Google Chrome Google Chrome OS
................................................................. .................................................................
................................................................. .................................................................
................................................................. .................................................................
3. Google Maps Google Earth IT PLANET - 8 (UBUNTU 18.04)
................................................................. .................................................................
................................................................. .................................................................
................................................................. .................................................................
4. Google Allo Google Duo
................................................................. .................................................................
................................................................. .................................................................
................................................................. .................................................................
E. Answer in 1-2 sentences.
1. What do you mean by Google Apps?
.................................................................................................................................................... 103
....................................................................................................................................................
F.PM PUBLISHERS PVT. LTD.2. How does Google Maps work?
.....................................................................................................................................................
G. PMP .....................................................................................................................................................
104
3. What is the purpose of Google Glass?
.....................................................................................................................................................
.....................................................................................................................................................
4. What is Google Android OS?
.....................................................................................................................................................
.....................................................................................................................................................
5. How does Google Photos store your pictures?
.....................................................................................................................................................
.....................................................................................................................................................
Answer Briefly.
1. What is Google? Who invented it & when?
.....................................................................................................................................................
.....................................................................................................................................................
.....................................................................................................................................................
2. What do you mean by Google Drive? Write down its uses.
.....................................................................................................................................................
.....................................................................................................................................................
.....................................................................................................................................................
3. What is the function of Google Translate app? How does it work?
.....................................................................................................................................................
.....................................................................................................................................................
.....................................................................................................................................................
4. What is YouTube? What is its purpose?
.....................................................................................................................................................
.....................................................................................................................................................
.....................................................................................................................................................
5. What is Google play? Why do we use it?
.....................................................................................................................................................
.....................................................................................................................................................
.....................................................................................................................................................
Application Based Question.
Ram went to his friend’s home. There he saw a device which looked like a speaker. His friend
was asking some questions to that device and getting back answers from it. Ram wants to know
the name of that device. Help him.
............................................................................................................................................................
............................................................................................................................................................
Discover More
Manage Your Calendar App
Nowadays, most of the people are choosing to use calendars in computers and mobile devices to keep
track of events in their personal and professional lives more easily. In addition, students might use
calendars to keep track of their class schedules.
The following steps guide you through the process of managing your computer or mobile device
calendar.
$ Run the calendar app.
$ To add a new appointment, tap or click the Add or New Appointment button and then enter the
title or subject of the appointment, its date, time, location, and other information. Tap or click the
Save button to save the information to your calendar.
$ Specify repeating information for appointments that occur at the same time over multiple
occurrences, such as a class that meets every Monday from 09:30 a.m. to 11:30 a.m.
$ View your appointments on a daily, weekly, or monthly calendar by tapping or clicking the
appropriate choice in the Calendar app.
$ To edit an appointment, meeting, or event on your calendar, open the item by tapping or clicking
it, make the necessary changes and then save the changes.
$ To delete an appointment, meeting, or event on your
calendar, open the item by tapping or clicking it, and
then tap or click the Delete button to delete it. If
necessary, confirm the deletion. If you are deleting a
recurring item on the calendar, the Calendar app may
ask whether you want to delete one occurrence or the
entire series of appointments, meetings, or events.
$ Calendar app allows you to share your appointment,
meeting, or event with other persons whom you want to
make aware about your appointments.
PMP
Technology Trailblazers
IT PLANET - 8 (UBUNTU 18.04)
Sundar Pichai
105
? CEO: Google & Alphabet
Sundar Pichai is a computer engineer and the current CEO of Google Inc.
Born in Chennai, India, Pichai was bright and creative from a young age.
Having received his education from some of the most prestigious institutions
in the world, he worked in engineering and product management at McKinsey
& Company before becoming a part of Google.
Pichai had joined Google years ago in 2004 as a product manager and led the
innovative efforts for several of Google's products including Google Chrome
and Chrome OS which went on to become highly successful. Eventually, he
took over the management of other Google products like Gmail and Google
Docs, and rose through the ranks rapidly. On 10 August 2015, Sundar Pichai
became the CEO of Google. On 3 December 2019, Sundar Pichai also became
the CEO of Alphabet Inc.
8 App Development
Topics Covered
•Introduction to App •Android and iOS •Types of Apps •Categories of Apps •Working of Apps
•Developing an App •Project: Creating an App for Android •Creating a HelloWorld App
Introduction to App
An app, sometimes called application software, consists of
programs designed to make users more productive and/or assist
them with personal tasks. It can run on our mobile phone,
computer, Internet or any other electronic device.
The app is a modern name for the word application or
software. The term ‘app’ is originally referred to as any mobile
or desktop application. But as more app stores have emerged to
sell mobile apps to smartphone and tablet users, you probably
only hear the word ‘app’ in reference to a mobile app and web
app, which is a small piece of software running on a website.
PM PUBLISHERS PVT. LTD. Apps
PMP
There are thousands of apps designed to run on today's smartphones and tablets. Some apps
can be downloaded for free, while others must be purchased from an app store. Apple's App
Store and Google's Play Store are two examples of popular app stores.
Apple’s App Store Google’s Play Store
Android and iOS
Most of the mobile devices run on iOS or Android.
iOS is an operating system developed and supported by Apple and is
used only on their own iPhones and iPads. In other words, in the
Apple universe, they control both the hardware and the software.
Android is an operating system for mobile computing devices
developed by Google. It is widely used on smartphones and tablet
computers. Google sells a few devices of its own but various
hardware manufacturers install Android as the operating system for
their devices.
Types of Apps
Apps are software programs that provide specific functionality to your phone or tablet in a
simple, more user-friendly way. Nowadays, there seems to be an app for everything. Whether
it is checking up on breaking news, chatting with friends via social networking or even booking
last minute holidays, there’s an app out there to help you. But these apps are divided into
three main types. 2. Web App 3. Hybrid App
106 1. Native App
NATIVE APP
Native Apps are developed for a particular Native
platform or device. Apps built for systems like iOS, App
Android, Windows phone, and Blackberry cannot
be used on a platform other than their own. In
other words, you won’t be able to use Android
app on iPhone. The majority of the apps on your
mobile device are native apps. They’re installed
directly onto the device. These apps are distinctly
accessible from app stores of their kind. Native
apps offer the fastest, most reliable and most
responsive experience to users.
Native apps have access to various devices of a phone, such as its camera, microphone,
compass and address book. It is still possible to use the alternatives, but using native is the
easiest. In addition, users can use some apps without an Internet connection.
WEB APP
Web apps are actually websites that provide a user with experience similar to native apps.
Web apps are not deployed to an app store; rather, they are deployed to a web server and
users access them in a web browser from any device, whenever there is an Internet
connection. Developers write the Web app by using technologies including HTML5, CSS, and
JavaScript. Many web apps use responsive design, which means the app displays properly on
any computer or mobile device.
Both the website and web app run on browser, but the major difference is that website
generally gives information whereas a web app provides functionality. For example, Wikipedia
is a website; it provides information, and Facebook is a web app; it provides functionality.
In contrast, a mobile app is a software you download from app store of a mobile device or
other location on the Internet to a smartphone or other mobile device. A mobile web app is a
web app that is optimized for display in a browser or on a mobile device, regardless of screen
size or orientation.
PMP
HYBRID APP IT PLANET - 8 (UBUNTU 18.04)
A hybrid app is the combination of both native and web app elements. Native is developed for 107
specific platform and installed on the computing device. Web app is generalized for multiple
platforms and not installed on computing device but made available over the Internet through
browser.
Like native apps, hybrid apps are developed for specific platforms and deployed to an app
store. They can access many hardware features of a device, such as its camera. Like web apps,
they are built with HTML5, CSS, and JavaScript. Developers use development tools to package
this code with a browser and prepare it as a native app to deploy to popular app stores.
In this way, hybrid apps are cross-platform, means the same code can run on many mobile
platforms. This approach often saves development time and costs, but may not provide a
consistent user experience or fast performance on all devices.
Categories of Apps
Nowadays, mobile phones are affordable across the world, so the app industry has absolutely
exploded in the last few years. The persons who were not using the app in the past are now
using it. Apps have become an integral part of today’s life. People are using mobile phones not
only to make calls, but mainly for using apps. They tend to do business, communicate,
entertain and play games, educate themselves, etc. by using apps. This has lead to the
development of many different types of apps.
Apple's App Store and Google's Play Store are two popular app stores which contain many
app categories as well as subcategories.
Now, we will discuss some of the popular app categories and their uses.
GAMING APPS
Gaming app helps the user improve their cognitive skills, such as attention and focus. Some
gaming apps encourage children to learn through play. Game apps also help find friends who
play the same game and post their scores on social media.
Examples of game apps you can play by yourself or with friends or others are:
Clash of Clans Candy Crush Saga Angry Birds Go
PM PUBLISHERS PVT. LTD.
Temple Run Solitaire Trivial Crack
PMP
BUSINESS APPS OR PRODUCTIVITY APPS
Modern-day smartphones are capable of performing many complex tasks on the run.
Productivity apps are developed to help us be more productive.
Examples of productivity apps are:
Google Calendars Translators To-do-list
Evernote Image Editing Dropbox
ENTERTAINMENT APPS
Entertainment apps are designed to entertain the users. These apps have a tendency to keep
users engaged, logged in, and always checking for updates. Entertainment apps are
distinguished from gaming apps because they often have quite different goals, even though
both of them seek to entertain the user.
Examples of entertainment apps are:
Netflix TikTok Talking Tom Cat
Amazon Prime Video YouTube Hotstar
UTILITY APPS
Utility app is used by everyone of us on a daily basis. These are handy tools that help you
perform simple tasks.
Examples of utility apps are:
Flashlight QR or Barcode Reader Internet Speed
108 Calculator SHAREit CamScanner
TRAVEL APPS
The main purpose of Travel apps is to make your traveling easier, more comfortable, fun and
informative. You can book your flights, hotels, trains, taxis, in fact all modes of transport with
the use of a Travel App. These apps also help you find unknown locations.
Examples of travel apps are:
Google Earth Google Maps MakeMyTrip
Goibibo Ola Uber
Google Trip TripAdvisor Airbnb
EDUCATIONAL APPS
Educational apps are making things easier for children to understand. These apps can make
children more interactive. Kids can learn while playing educational game apps. Moreover, many
educational apps are useful for teachers as well—organizing a teaching process, better
educating themselves, etc.
Examples of educational apps are:
Ted Duolingo Khan Academy
Lynda PhotoMath SoloLearn
PMP
Udacity YouTube Coursera
SOCIAL NETWORKING APPS
Social networking apps enable you to connect with people, who share similar personal or
professional interests. The main purpose of using social networking apps is to keep track of
what is going on in the lives of friends, family and colleagues, especially the people whom you
do not meet regularly. It also helps us expand the circle of friends and business contacts.
Examples of social networking apps are:
Facebook LinkedIn Google +
Instagram WhatsApp Telegram
GroupMe Twitter Snapchat
COMMUNICATION APPS IT PLANET - 8 (UBUNTU 18.04)
Communication apps enable you to impart or interchange thoughts, opinions, or information
by speeking, writing, or through signs.
Examples of communication apps are:
WhatsApp TrueCaller Imo
Skype hike FaceTime
SHOPPING APPS
Shopping apps enable you to purchase product by placing the order and pay through
credit/debit card on the Internet so that the product is delivered at your home.
Examples of shopping apps are:
Amazon Flipkart Snapdeal
Paytm Mall ShopClues ebay 109
Working of Apps
Apps are used to do specific function in your computer and mobile device. Mobile apps mostly
run on Android, Apple and Windows phone. Android has a huge market and lots of people are
using it, so in this chapter we will take the example of Android phone.
Your android phone comes with some built-in apps, and you can install further apps to make
your device perform the tasks you need. You can download apps from Google’s Play Store or
other sources, run them as needed, and switch quickly among them.
RUNNING AN APP
If you need to use an app on your mobile device, you have to run it. You can run any app
from the Apps screen of Android mobile phone. You can run multiple apps at once. Each app
appears full screen, so you work in a single app at a time, but you can switch from one app to
another as needed. You can switch apps quickly by using the Recent Apps list.
1. Tap All Apps button from the Home Screen. The Apps screen appears.
If necessary, swipe The app opens
2 left or down to in full screen.
display more apps. Now, you can
use it.
2. Tap the app
you want to
use.
PM PUBLISHERS PVT. LTD.
In this example,
PMP1 we have selected
Calculator app.
INSTALLING AN APP USING GOOGLE PLAY STORE
Google Play Store has many types of apps available for your Android device to install and
work. If you need to install a particular app (Temple Run), you can navigate that app in the
Google Play store in Game category. You can also use the Search feature of Play store for
saving time. Searching offers a list of matches that you can explore in detail. When you find an
app you want, you can install it.
1. Tap the Play Store icon on Apps screen.
The Play Store app opens and displays Google Play screen.
2. Type the name of the App (Temple Run) in the Search.
2
A list of matching results will appear.
1 3. Tap the app you want to install.
110 The icon of app will appear in the App Screen. 3 App info page
will appear.
4. Tap on
4 Install.
Downloading
and installing
the app process
will start.
Now, you can run this app by tapping on its icon.
INSTALLING A NEW APP MANUALLY
The normal way to install an app on your Android phone is by downloading it from the Google
Play Store. But you can also load an app onto your device manually. For that, you acquire a
package file containing the app you want to install. You then transfer the package file to your
phone and install the app.
To allow installing the apps manually in your phone, you need to enable the option of
installation of apps from unknown sources by using Settings > Security > Unknown sources.
Android apps are saved with .apk extention.
PMPSettings icon Security option Unknown sources option
REMOVING AN APP
Every app you install takes up some of your device storage space and appears on the Apps
screen. When you no longer need an app you have installed, you can remove it from your
device. The app remains available to you on Google Play store, so you can easily reinstall it if
you want. You can remove an app by following these steps.
1. Tap the Settings icon on the Home screen or the Apps screen. IT PLANET - 8 (UBUNTU 18.04)
Settings screen will appear.
2. Tap or select Apps Management.
Apps Management screen will appear.
3. Scroll down the list until you find
the app you want to remove and
select it.
1 2 App info screen appears.
4. Tap on
3 4 Uninstall.
The app will
be removed.
Note: You should not remove the apps that come pre-installed in Android, you can only 111
remove the apps you have installed.
Developing an App using MIT App Inventor
MIT App Inventor is an open-source web application originally provided by Google, and now
maintained by the Massachusetts Institute of Technology (MIT). It lets you develop apps or
applications for Android phones using a web browser. It is very easy and user friendly. The App
Inventor programming environment has three key parts:
1. Component Designer: You use it to select components and specify their properties.
2. Blocks Editor: You use it to specify how the components will work.
3. Android Device (phone/tablet) or Emulator: You use an Android device to run and test
your app as you are developing it. If you don’t have an Android device, you can test the
apps you build by using the Android emulator that comes with the system.
Note: MIT App Inventor is compatible with Mozilla Firefox, Google Chrome, and Safari. In this
chapter, we will use Mozilla Firefox as a Web browser.
Project: Creating an App for Android
Start
PM PUBLISHERS PVT. LTD.
In this App, you will add five components on the
PMP screen—
! Textbox component is used to enter text.
! Button component is used to initiate an action.
! Label component is used to show text on the
screen.
! TextToSpeech enables your Android device to speak
the text.
! Image will enhance the appearance of the app.
Creating a ‘HelloWorld’ App
Follow the instructions and steps to develop your first android app called HelloWorld.
1. Create a Google Account.
With your Google account,
1 you can use all the services
of Google like gmail, Google
Drive, etc.
If you already have a Google
Account, skip this step.
112
2. In the Address bar of your
2 Web browser, type
www.appinventor.mit.edu
3 and press the Enter key.
The home page of app
inventor appears.
3. Click on Create apps!.
Google Sign in page will appear.
4. Type user name and password that you have created in step 1 and click on Sign in (not shown).
The Welcome to App Inventor page appears.
5. Click on Continue.
6 6. Click on Projects option.
7
A menu will appear.
7. Click on Start new
project.
5 Create new App Inventor
project box appears.
PMP
8 8. Type the name for your project in the Project name box.
9 In this example, we have given the name ‘HelloWorld’.
9. Click on OK.
App Inventor opens the Component Designer window.
In Component Designer window, you will create the look and feel of your app. You can choose
components like Buttons, Images, Text boxes and functionalities like Text-to-Speech.
The Component Designer window is divided into four areas:
Viewer Components
List
Components Components IT PLANET - 8 (UBUNTU 18.04)
Palette Properties
• Components Palette: On the left, there is a Palette, which is a list of components from 113
which you can select.
• Viewer: To the right of the Palette is the white area called the Viewer. Here you can
place the components to map out how you want your app to look like.
• Components Lists: To the right of the Viewer is the Components list. Any component
that you place into the Viewer will also show up in this list.
• Components Properties: To the far right is the Properties of components; when you
click a component in the Viewer, you will see its Properties listed here. Properties are
details about each component that you can change.
10 13 10. In Components Palette, open the
User Interface drawer if it is not
12 open.
11
11. Click and hold on the word TextBox
14 in the Palette.
12. Drag your mouse over to the Viewer.
13. Release the mouse.
A new TextBox will appear on the
Viewer. It will also appear in
Components List and Properties.
14. Click and drag the word Button from
the Palette to the Viewer.
A new Button will appear on the Viewer.
It will also appear in Components List
and Properties.
PM PUBLISHERS PVT. LTD.
15 16 15. Click and drag the word Label from
114 PMP the Palette to the Viewer.
18
19 A new Label will appear on the Viewer.
17 It will also appear in Components List
and Properties.
In the Components List, Button is
displayed as ‘Button1’. You can rename
it.
16. Click on the word Button1 in
Components List.
17. Click on Rename.
Rename Component dialog box appears.
18. Type the new name for the
component. In this example, we
have given WelcomeButton as new
component name.
19. Click on OK.
The new name for the button will appear in the Components List. You might have also noticed
that in the Viewer, Button still has the words ‘Text for Button1’ displayed on it. You probably
don’t want that in your app, so go ahead and change it in the Text Properties.
20. Click on the Button in Viewer.
21. In the Components’ Properties,
click the area under Text and type
20 the name for the button. You’ll
see the text changes in the
Viewer.
In this example, we have changed the
name as Welcome.
You can also change other properties
21 of the selected component, e.g. font
size, font shape, color of the text, etc.
In the Viewer, the Label has the words ‘Text for Label1’ displayed on it. You probably don’t
want that in your app, because it is used to show your text on screen, so go ahead and
remove it in the Text Properties.
22. Click on the Label component in
Viewer.
22 24 23. In the Components’ Properties,
click the area under Text and
remove the text written in it.
You’ll see that the text will be
removed from Viewer.
24. Click the area under FontSize, and
23 change the font size from 14 to
25.
It will show the final message in a
new font size.
PMP
25. In Palette, open the Media
drawer. IT PLANET - 8 (UBUNTU 18.04)
26. Click and drag the word
25 TextToSpeech from the Palette to
the Viewer.
This component will not appear in
the Viewer.
26 It will drop down under ‘Non-
visible components’ because it is
not something that will show up
on the app's user interface. It's
more like a tool that is available
to the app.
It will also appear in Components List 115
and Properties.
27 32 27. In Components Palette, open the
28 31 User Interface drawer.
29 34
28. Click and hold on the word Image
33 in the Palette.
29. Drag your mouse over to the
Viewer.
30. Release the mouse.
A new Image will appear on the
Viewer. It will also appear in
Components List and Properties.
31. Click on Upload File in Media
section.
32. Click on Choose File.
Open Dialog box will appear.
33. Navigate the file you want to upload and click
on it.
Note: You should upload the small size picture as
bigger picture will cover the whole screen.
34. Click on Open.
PM PUBLISHERS PVT. LTD.
PMP
The name of uploaded picture appears here.
35 35. Click on OK.
36 37 The name of uploaded picture will
38 appear in Media section.
39 36. Click on Image1 in the Components
list.
37. Click on Picture box in the
Properties panel.
A box will appear with the name of
uploaded image.
38. Click on the image name.
39. Click on OK.
The image file will appear in the
Viewer pane.
You can adjust the setting of image
from the Properties pane.
116
The components we have added to the HelloWorld app
Component type Palette group Name of component Purpose
TextBox User Interface TextBox1 Enter the text
Button User Interface WelcomeButton Press to show the message
Label User Interface Label1 Show the message
TextToSpeech Media TextToSpeech1 Speak the message
Image User Interface Image1 Show the image
Testing your app in Android device
You can view and test your app on an Android device as you create it. If you have an Android
device and an Internet connection with WiFi, do the following:
1. Tap the Play Store icon on Apps screen.
Play Store app opens and displays the Google Play screen.
2 2. Type MIT AI2 Companion in the Search.
App info page will appear.
3. Tap on Install.
Downloading and installing the app
1 3 process will start.
The icon of app will appear in the App
Screen.
Now, you can run this app by tapping
its icon.
PMP
App appears in the device after tapping its icon.
4 4. In App Inventor (in the browser), click on
5 Connect.
5. Click on AI Companion.
Connect to Companion dialog box appears showing the QR code (quick IT PLANET - 8 (UBUNTU 18.04)
response code) and six digits code.
QR code Six digits 6. On your mobile If everything is
code device, select Scan done, you
QR Code and then should see the
hold your device up HelloWorld app
to the QR code on running on
the computer screen your mobile
to scan it. device.
6 OR Enter the six
digits code shown on
the computer screen Now, whatever changes you will do 117
into the mobile in the App Inventor, those changes
device. will appear on the device as well.
Until now, your connected mobile device can only show the App but cannot do any thing in it as we
haven’t instructed it to do anything in the app. To allow every component you add in the Component
Designer work, you have to move over to the Blocks Editor. In blocks editor, you create the code to
make that component work according to you.
Blocks Editor
In the Component Designer, you have added TextBox, Button, Label, TextToSpeech and Image
components as the building blocks for your first app. Now, let’s make your app work when you
tap the button. You do this with the Blocks Editor by instructing the components what to do
and when to do it.
1 1. Click on
Blocks.
Backpack The App
Inventor
Built-in Block Viewer opens Block
Blocks Editor
window.
ComponentsPM PUBLISHERS PVT. LTD.
Blocks
PMP
Trash
Main parts of Blocks Editor are given below:
Built-in Blocks: These blocks are always available for you to use in your app.
Components Blocks: These are the blocks you have chosen for your app.
Block Viewer: This is the place where you assemble the blocks for your app.
Trash: It is used for deleting unneeded blocks.
Backpack: You can drag blocks into the Backpack icon so that you can use them later by
dragging items out of the backpack and use them between the apps. Backpack retains a copy
of your blocks even when you exit App Inventor.
1 1. Click on WelcomeButton component.
118
A bunch of blocks related to your component appears in
the viewer so that you can use them to build the behaviour
2 of button.
2. Click on when WelcomeButton.Click do block.
Here block is showing WelcomeButton, because we have
renamed the components from Button1 to WelcomeButton.
Otherwise it will show ‘when Button1.Click do’.
When you click on any block, only that block will remain in
the viewer, all other blocks will disappear.
3 PMP You will notice that
4 the word when is
included on the IT PLANET - 8 (UBUNTU 18.04)
6 block, which means
5 that this block will be
launched when the
78 button on your app is
clicked. It is called an
Event Handler.
3. Click on Label1
component.
A bunch of blocks related
to your components
appears in the viewer.
4. Click on set
Label1.Text to
block.
This block instructs your
app to display the text.
The selected block will
appear on the Viewer.
5. Click on set
Label1.Text to block
again.
6. Drag this block and
snap it into when
WelcomeButton.Click
do block.
7. Click on Text block in
the Built-in area.
A bunch of blocks related
to Text component
appears.
8. Click on Join block.
119
9 PM PUBLISHERS PVT. LTD. 9. Drag the Join block and snap
it into set Label1.Text to
10 PMP block.
11
12 Join block appends all of the
inputs to make a single string.
14
13 By default, Join block has two
place folder to snap the
15 16 blocks, but we need three for
the app.
120
10. Click on the blue setting
icon of Join block.
A pop-up balloon appears
showing two strings in the
Join block. In this app, we
need three strings.
11. Click on the string block.
12. Drag and snap it under
two strings in the Join
block.
You can click anywhere to
remove the popup balloon.
You will notice that the
Join block now has three
placeholders to snap the
block.
13. Click on Text block in the
Built-in area.
14. Click on String block.
This string block can contain
characters.
15. Drag and snap it in the
first placeholder of Join
17 block.
16. Right-click on the String
block. A menu appears.
17. Click on Duplicate.
A duplicate of String block
appears.
18. Drag and snap it in the
third placeholder of Join
block.
18
19. Type the text in both
strings.
In this example, we have
19 written Hello in first string
block and , how are you!! in
second string block.
PMP 20. Click on TextBox1
20 component.
21 IT PLANET - 8 (UBUNTU 18.04)
A bunch of blocks related to
your components appears in
the viewer. Now search for
TextBox1.Text block by
scrolling down.
21. Click on TextBox1.Text
block.
This block lets the users
enter text in a text box.
22. Drag and snap the
selected block in the
22 second placeholder of
Join block.
121
23PM PUBLISHERS PVT. LTD.24 23. Click on TextToSpeech1
122 component.
PMP25
26 A bunch of blocks related to
your components appears in
the viewer.
24. Click on call
TextToSpeech1.Speak
message block.
TextToSpeech block will make
the phone speak the text.
25. Drag and snap the
selected block inside the
WelcomeButton block
under the Label1 block.
As this block is inside the
Button block, it will run
when the button on your app
is clicked.
26. Right-click on the join
block. A menu appears.
27 27. Click on Duplicate.
A duplicate of Join block with
all three strings appears.
28. Drag and snap the Join
block in the TextToSpeech
block.
Now, whatever is shown in
the Label is also audible in
28 your mobile device.
Running the App
After completing the app, you can run and test it in your connected android device or
emulator.
In this example, your device will show a Text box, button (Welcome) and an image.
When you write any text (students) in the Text box and press the button, the app will show a
message Hello students, how are you!! and speak this message too.
1. Go to the connected android device.
You have already learnt how to connect with android device.
In the android device, you will use your finger to tap and work.
2 2. Tap the Textbox.
4 A virtual keyboard will appear.
3. Type the text (Students) with the keyboard.
4. Tap the Welcome button.
Android device After clicking or tapping the button, a
message Hello students, how are you!!
will appear along with sound of
message.
PMP
Finish
IT PLANET - 8 (UBUNTU 18.04)
Testing your app in Emulator
123
If you don’t have an Android device, you’ll need to perform some additional
setup in order to use the emulator. For that, you have to download and install
app inventor software into your computer.
You can download the app inventor from
“http://appinventor.mit.edu/explore/ai2/linux.html”. Typically, it will go into
your Downloads folder. From there you can install it.
The aiStarter is a program which manages communication between the Web
browser and the Android device. It must run whenever you use the emulator.
This can be done with the path:
/usr/google/appinventor/commands-for-Appinventor/aiStarter
1 1. After downloading, installing and
launching the software, click on
2 Connect in App Inventor (in the
browser).
2. Click on Emulator.
After some time, depending upon the speed of your computer, the emulator
will appear on the screen showing your app. Now whatever changes you will
do in the App Inventor, those changes will also appear on the emulator.
Self-Evaluation CHECKLIST
After reading the chapter, I know these points:
$ I know that an app, sometimes called application software, consists of programs
designed to make users more productive and/or assist them with personal tasks.
$ I know that apps are divided into three main types — Native app, Web App and
Hybrid App.
$ I know that Apple's App Store and Google's Play Store contain many app categories
as well as subcategories.
$ I know that the normal way to install an app on your Android phone is by
downloading it from the Google Play Store app.
$ I know that App Inventor is an open-source web application. It lets us develop
apps or applications for Android phones using a web browser.
$ I know that The App Inventor programming environment has three key parts:
Component Designer, Blocks Editor, Android device or emulator.
$ I know that Blocks Editor is used for instructing the components what to do and
when to do it.
PM PUBLISHERS PVT. LTD.
Exercises
PMP
A. AgreeTick [ü] the correct answer.
Disagree
B. 1. iOS is developed and supported by .................. and is used only on their own devices.
124
a. Google b. Apple c. Android
2. ........................ apps are developed for a particular platform or device like iOS and Android.
a. Web b. Hybrid c. Native
3. ........... App helps the users improve their cognitive conditions, such as attention and focus.
a. Entertainment b. Gaming c. Utility
4. You can run any app from the ............................... of Android mobile phone.
a. App Screen b. Display c. Output Screen
5. In ............................... window, you will create the look and feel of your app.
a. Blocks Editor b. Properties c. Component Designer
6. ........................... is used for instructing the components what to do and when to do it.
a. Properties b. Blocks Editor c. Component Designer
Write ‘T’ for True and ‘F’ for False statements.
1. Web apps provide a user an experience similar to native apps.
2. Hybrid apps are developed for a particular platform or device.
3. Utility app is used by everyone of us on a daily basis.
4. Android apps are saved with .apk file extension.
5. To test your app on the emulator, click on Connect and then ai companion.
6. Backpack retains a copy of your blocks even when you exit app inventor.
C. Fill in the blanks.
1. A ............................... is optimized for display in a browser or on a mobile device.
2. ............................... app enables you to connect with people who share similar personal or
professional interests.
3. ...................... apps list is used to switch from one app to another quickly as needed in
android device.
4. ....................................... option enables you to install the apps manually in your mobile.
5. Any component that you place into the ............................... from Components Palette, will
also show up in Components list.
6. After creating, you can ............................... your app in Android device or in emulator.
D. Write the uses of the following.
1. Business Apps: ............................................................................................................................
.....................................................................................................................................................
2. Travel Apps: ................................................................................................................................
.....................................................................................................................................................
3. Communication Apps: ................................................................................................................
.....................................................................................................................................................
PMP
4. Educational Apps: .......................................................................................................................
.....................................................................................................................................................
E. Differentiate between the following.
1. Android iOS
................................................................ .................................................................
................................................................ .................................................................
................................................................ .................................................................
2. Native App Web App
................................................................. .................................................................
................................................................ .................................................................
................................................................ .................................................................
F. Answer in 1-2 sentences.
1. What do you mean by App? IT PLANET - 8 (UBUNTU 18.04)
.....................................................................................................................................................
.....................................................................................................................................................
2. Name the different types of apps.
....................................................................................................................................................
.....................................................................................................................................................
3. What is an App store?
....................................................................................................................................................
.....................................................................................................................................................
4. Name the components of Blocks Editor window.
.................................................................................................................................................... 125
....................................................................................................................................................
G. Answer Briefly.
1. What do you mean by hybrid apps? Explain.
....................................................................................................................................................
.....................................................................................................................................................
....................................................................................................................................................
2. Why do we need web app?
....................................................................................................................................................
.....................................................................................................................................................
....................................................................................................................................................
3. What do you mean by MIT App inventor?
....................................................................................................................................................
.....................................................................................................................................................
....................................................................................................................................................
4. What is the purpose of Blocks Editor? Name its main parts.
....................................................................................................................................................
.....................................................................................................................................................
....................................................................................................................................................
H. Application Based Question.
Saanvi wants to wish ‘Happy Birthday’ to her best friend in a different way. One of her friends
suggests to make App in MIT App Inventor. She has made an app to say ‘Happy birthday’ to her
friend. Now, she wants to run the App to wish her friend but she doesn’t know how to run it.
Help her by telling the option for running the app.
...........................................................................................................................................................
PM PUBLISHERS PVT. LTD.
Discover More
PMP
Voice Command for personal Assistant
Many mobile operating systems include a virtual personal assistant like Google Assistant in Android and
Siri in Apple that processes voice commands and performs certain tasks. For example, you can issue
voice commands to set an alarm, add an appointment, send a text message, or run an app. Given
below are some of the voice commands.
TASK SAMPLE VOICE COMMAND(S)
Change phone settings “Turn on Wi-Fi.” or “Turn off Bluetooth.”
Dial a number “Call Reema’s Cell” or “Call Home” or “Dial 110088989.”
Obtain information “When was Mahatama Gandhi born?”
“How many bits are there in a byte?”
Obtain driving instructions “Navigate to Rajiv Chowk, New Delhi, India.”
Perform a search “How is the weather in Punjab?”
“Search Dominos Pizza outlets in Delhi.”
Run an app “Run calculator”
Send a text message “Text Haqe, meet me in the office.”
126 Set a reminder “Remind me to attend a workshop”
Set an alarm “Set an alarm for 6:00 a.m. tomorrow.”
PMP Activity Section
Lab Activity IT PLANET - 8 (UBUNTU 18.04)
Create an app on Computer Parts. Add a background image to the screen and six buttons,
namely, Parts of Computer, Input Devices, Processing Device, Storage Devices, Output
Devices and Back button. If you click on any of the buttons, appropriate image should be
opened with the spoken message regarding the topic.
Note: Your background images, spoken messages may vary.
127
PM PUBLISHERS PVT. LTD.9 Python - Introduction
PMP Topics Covered
•Programming Language •Introduction to Python •Character Set •Tokens •Comments •Statements •Data
Types •Variables •Defining Input and Output in Python •Error Handling in Python •Programs in Python
Programming Language
A computer language is a medium of communication between the user and a computer.
Computer language has its own character set, keywords and symbols, which are used for
writing a program.
Computer programs are instructions to a computer. These instructions tell a computer to
perform the tasks necessary to process the data into information. The process of writing these
instructions (program) is called programming. The people who can write these programs are
called programmers.
A programming language is a set of words, symbols and codes that are used to write a
computer program. Python is one such programming language.
Introduction to Python
Python is a high level, structured, open source programming language that supports the
development of wide range of applications from simple text processing to world wide web
browsers to games. Python was founded by Guido Van Rossum in early 1990's. It is named
after “Python's Flying Circus”, a comedy program.
FEATURES OF PYTHON PROGRAMMING
The growth and usage of Python are increasing day by day due to the following features:
1. Python is easy to use and learn.
2. Python is an open source language and available free at https://www.python.org/downloads/.
3. Python can run equally on different platforms, such as Windows, Linux, Unix and
Macintosh. So it is a portable language.
4. Python can be used for Graphical User Interface (GUI) programming.
5. It is a high level programming language and user friendly in nature for developers.
6. Programming in Python is fun. It's easier to understand and write coding in Python than
any other high-level language. The syntax feels natural. For example:
a=2
b=3
sum = a + b
print(sum)
Even if you have never programmed before, you can easily guess that this program adds
two numbers and prints it.
7. Python is an interpreted language that executes the code line by line at a time. This makes
128 the debugging process easier.
PMP8. Python supports both procedure-oriented and object-oriented programming.
9. Python is an extensible language, it means that it can be extended to other languages. IT PLANET - 8 (UBUNTU 18.04)
10. Programs written in Python are typed dynamically which means that the type of the value 129
is decided at run time. There is no need to specify the type of data while declaring it. It's
not necessary to add semicolon at the end of the statement. Python enforces you to apply
proper indentation. These small things can make learning much easier for beginners.
Due to these features and variety of applications of Python, people and organizations are
preferring this language over other languages.
PYTHON PROGRAMMING STYLES
Python is a general purpose programming language and supports multiple structure approach.
Following paradigms are supported by Python:
! Object Oriented Approach: Python allows the programmer to create classes and objects.
! Procedure Oriented Approach: The code can be grouped into functions in Python as in
procedure oriented approach. Stepwise execution of tasks is done using functions.
! Imperative: This style is useful for manipulating data structures and produce simple codes.
Combination of the above programming paradigms makes the Python language more flexible
and easy to use. Therefore, organizations are moving towards this language due to its multiple
programming paradigms approach.
INSTALLING PYTHON
Python comes in three versions: Version 1.0, Version 2.0 and Version 3.0. In this chapter, we
are using version 3.6 as it is pre-installed in Ubuntu 18.04.
Updating your System
You can update the system so that you can download the updated software packages.
1. Press Ctrl+Alt+T keys simultaneously from the keyboard to open Terminal.
2. Type sudo apt-get update after the $
sign.
2
3. Press the Enter key.
4 You will be prompted for your password.
4. Type the password and press Enter key
again.
The updating process will begin. It may take some time. After updating, the prompt will
appear again to accept the next command.
Installing Python
1. Type sudo apt-get install python3.6
1 after the $ sign.
2. Press the Enter key.
You will be prompted for your password.
3. Type the password and press Enter key
again.
As you can see in the screenshot above, Python 3.6 is already installed in Ubuntu 18.04 as mentioned
above.
Running Python
1 1. Type python3 after the $ sign.
2. Press the Enter key.
You will get a python prompt
(>>>).
Let’s enter a command “Welcome to Python” at the prompt.
1. Type print (“Welcome to Python”)
after the python prompt.
Make sure to include the brackets and
double quotes (" ").
1 2. Press the Enter key.
If you have entered the command
correctly, you should see this:
Welcome to Python
>>>
PM PUBLISHERS PVT. LTD.
PMP
The prompt (>>>) should reappear to tell you that it is ready to accept more commands.
In the above program the word print is a type of Python command called a function, and it
displays whatever is inside the quotes on the screen.
Great! You’ve just created your first Python program.
Exiting from Python
After working in Python, you can exit from Python and return to Ubuntu prompt.
1. Type exit() after the python
prompt.
1 2. Press the Enter key.
Ubuntu prompts appears.
INTEGRATED DEVELOPMENT AND LEARNING ENVIRONMENT (IDLE)
Python IDLE is a graphical program for writing python programs and test them. It is very easy
and user friendly. You can always start writing Python code with IDLE. It is simple and has nice
syntax highlighting ability.
Installing Python IDLE
1 1. Type sudo apt-get install idle-python3.6 after
the $ sign.
2. Press the Enter key.
You will be prompted for your password.
3. Type the password and press Enter key again.
130 The downloading and installation process of the software package begins.
After installation, the prompt will appear again to accept the next command.
Running Python IDLE 1. Click on Show Applications icon.
Apps List screen will appear.
After installing, you can open Python IDLE. 2. Type idle in the Search bar.
2 3. Click on IDLE icon.
3
The Python shell will appear.
Prompt
This is the Python shell, which is a part of Python’s integrated development environment. An
Integrated Development and Learning Environment (IDLE) is the most popular graphics based
development environment for Python. It is easy to create, edit, debug a program in this
environment.
This window is called Interactive mode. The interactive mode screen shows the welcome
message with version details and the three greater-than signs (>>>) called the prompt. This is
a primary prompt which indicates that interpreter is executing the Python command. There is
also a secondary prompt (…) which indicates that interpreter is waiting for the input to
complete the statement. All the statements or expressions or commands are written after the
primary prompt in the Interactive mode window.
Let’s enter a command “Welcome to Python” at the prompt in the shell.
1. Type print (“Welcome to Python”)
after the python prompt.
Make sure to include the brackets and
1 double quotes (" ").
2. Press the Enter key.
If you have entered the command
correctly, you should see:
Welcome to Python
>>>
PMP
The prompt (>>>) should reappear to tell you that the shell is ready to accept more commands. IT PLANET - 8 (UBUNTU 18.04)
SAVING YOUR PROGRAM 131
The interactive mode is best for small programs and for the beginners. But we can't save the
commands in interactive mode for future use. For saving a program, you need to open and
write a program in another Python shell, called Script mode.
2
1. Open IDLE (Python GUI).
3 2. Click on File menu.
3. Click on New File.
An empty window will appear, with
Untitled displayed in the Menu bar.
This is another Python shell, which
is called Script Mode.
Creating, Saving and Running a program in Script mode
Let’s enter a command “Welcome to
Python” in Script mode.
1 1. Type print (“Welcome to
Python”)
2. Click on File menu.
2 3. Click on Save.
3PM PUBLISHERS PVT. LTD.Save As dialog box appears.
4
PMP By default the file will be saved in Python folder in
C: drive, but you can change the location.
4. Type the filename (MyFirstProgram).
The file extension of Python is .py.
5. Click on Save.
The Python will save the program in the specified
5 location.
6 The new filename will appear on
the Title bar.
7 6. Click on Run menu.
You can also press F5 key to run the program. 7. Click on Run Module.
If you’ve entered the
command correctly, your
saved file should run like
this in Interactive mode.
Now, if you close the shell window but leave the MyFirstProgram.py window open and then
132 choose Run > Run Module, the Python shell reappears, and your program will run again.
LINES AND INDENTATION
Python is very particular about program layout, especially regarding lines and indentation.
A Python program is made up of one or more physical lines. Each physical line may end with a
comment. The text written in the comments are ignored by Python.
In Python, the end of a physical line marks the end of most statements. Unlike other
languages, you don’t need to terminate Python statements with a semicolon (;).
Python uses indentation to express the block structure of a program. An indentation is an
empty space at the beginning of a line to signal the start of a new paragraph. Unlike other
languages, Python does not use braces, or other beginning/end symbols, around blocks of
statements; indentation is the only way to denote blocks.
Character Set
Character set is a set of valid characters that a language can recognize. Python uses the
traditional ASCII character set. Python version 3 source file can use any Unicode character. A
version 2 source file is usually made up of characters from the ASCII set (character codes
between 0 and 127). The ASCII character set is a subset of the Unicode character set. Python
version 2.7 also recognizes the Unicode character set.
PMP
Tokens
A token is the smallest element of a program that is meaningful to the interpreter. Tokens
supported in Python include identifier, keywords, delimiter, and operator.
IDENTIFIERS
A random name made out of letters, digits and underscore (_) to identify a function name, a
program name, a memory location (variable or constant) is known as identifier. Python is a
case sensitive language as it treats lower and upper case letters differently. Following rules
must be followed for creating identifiers:
! Must start with a letter A to Z or a to z or an underscore (_). IT PLANET - 8 (UBUNTU 18.04)
! Can be followed by any number of letters, digits (0-9), or underscores.
! Cannot be a reserved word.
! Python does not allow punctuation characters such as @, $ and % within identifiers.
! Class names start with uppercase letter.
! Starting an identifier with single underscore indicates that identifier is private.
Examples: shapeclass shape_1 shape_to_db
KEYWORDS
Keywords are the reserved words in Python and cannot be used as constant or variable or any
other identifier names. All the Python keywords contain lowercase letters only.
133
Following is the List of Python Keywords:
true false none and as
assert def class continue break
else finally elif del except
global for if from import
raise try or return pass
nonlocal in not is lambda
DELIMITER
The following characters and combinations are used by Python as delimiters in expressions, list,
dictionary, and various statements:
()[]{}
, : . ` =; @
+= -= *= /= //= %=
&= |= ^= >>= <<= **=
PM PUBLISHERS PVT. LTD.
PMP
The last two rows are the augmented assignment operators, which are delimiters, but also
perform operations.
The following ASCII characters have special meanings as part of other tokens.
' "#\
The following ASCII characters are not used in Python.
$?
LITERALS
The data items that never change their value throughout the program run are called literals.
Theoretically Literal means any number, text or other information that represents a value.
Python supports the following literals:
Literals Examples
String literals :: "hello" , '12345'
Integer literals :: 0, 1, 2, -1, -2
Long literals :: 89675L
Floating-point literals :: 3.14
Complex literals :: 12j
Boolean literals :: True or False
Special literals :: None
Unicode literals :: u"hello"
134 List literals :: [5, 6, 7]
OPERATORS
Operators are the special symbols that carry out arithmetic and logical computations. The
values operated by the operator are called operands. Following are the operators used in
Python:
1. Arithmetic Operators: Arithmetic operators are used to perform mathematical operations.
The various arithmetic operators are given in table below:
Operator Meaning Example
'+' Addition and concatenation in strings >>> 200+45
245
>>> "Good" + " "+ "Morning"
‘Good Morning’
'-' Subtraction >>> 100-20
80
>>> 80-160
-80
'*' Multiplication >>> 4*5
PMP
20
>>> 'python' *3
'pythonpythonpython’
'/' Divide >>> 28/4
7.0
>>> 50/6
8.333333333333334
'%' Modulos / Remainder >>> 67%9
4
'**' Exponentiation >>> 8**2
64 IT PLANET - 8 (UBUNTU 18.04)
2. Relational Operators or Comparison Operators: These operators are used to compare the
values. Following is the list of comparison operators:
Operator Meaning Example
'>’ Greater Than >>> 6>1
True
'<’ Less Than >>> 90>100
False
>>> 8<9 135
True
>>> 70<54
False
>=’ Greater than or equal to >>> 9>=5
'<=’ Less Than or Equal to True
'==’ Equal to >>> 5>=9
'!=’ ‘Not Equal to’ False
>>> 1<=2
True
>>> 20<=10
False
>>> 6==7
False
>>> 7==7
True
>>> 7!=4
True
PM PUBLISHERS PVT. LTD.3. Logical Operators: Logical operators perform Logical AND, Logical OR and Logical NOT
operations.
PMP
Operator Meaning Example >>> x=False
or If any of the operands is true then >>> x=True >>> y=False
condition becomes true. >>> y=False >>> x or y
>>> x or y False
and If both the operands are true True >>> x=True
then condition becomes true. >>> x=True >>> y=False
>>> y=True >>>x and y
not Reverse the state of Operand >>> x and y False
True >>> a=True
>>> a=False >>> not a
>>> not a False
True
4. Assignment Operators: These operators are used to assign value to the variables. Following
are the list of assignment operators:
Operator Meaning Example #Assign the value 30 to x
'=' Assign the value from right >>> x=30 #print the value of x
>>> print (x)
side to variable. 30
136
'+=' Add and assign the value >>> a=12
to the variable. >>> a+=2
>>> print (a)
14
'-=' Subtract and assign the value >>> a=12
to the variable >>> a-=2
>>> print (a)
10
'*=’ Multiply and assign the >>> a=12
value to the variable >>> a*=2
>>> print (a)
'/=' Divide and assign the value 24
to the variable >>> a=12
>>> a/=2
>>> print (a)
6.0
PMP
Operator Precedence
Operator precedence determines the order in which expressions are evaluated, so you can
predict the outcome of an expression. It can also determine the overall value of the expression.
For example, take the following expression: a = 8 + 6/2. Depending on whether the 8 + 6
expression or the 6/2 expression is evaluated first, the value can end up being 7 or 11. Python
follows operator precedence rules for solving the expression as shown in the table.
While solving the expression, operators follow Priority Operators Description
the table and evaluate according to the priority 1st () Parentheses
level. Operators on the same line have the same 2nd */% multiplication, division,
precedence and are evaluated left to right based modulus
on how they appear in the expression itself. 3th +- addition, subtraction
4th = assignment
Now for the same expression a = 8 + 6 / 2,
according to this table, the division is evaluated IT PLANET - 8 (UBUNTU 18.04)
before addition, so the value will be 11.
Comments
Comments are very important while writing a program in any language. Python ignores the text
written in the comment. Python supports the following ways to use comments in a program:
SINGLE LINE COMMENTS
Python uses hash (#) symbol for writing a comment for a single line.
Example:
#This is the start of program This is a single line comment
#print hello in python This is a single line comment 137
print (“Hello”) This is a statement
MULTI-LINE COMMENTS
Python uses triple quotes ' ' ' or “ “ “ for multi-line strings.
Example
“ “ “ This is an example of
multiline comment” ” ” # multi-line comments
Statements
Simple and compound are two types of statements in Python source file. Unlike some other
languages, Python has no “declarations” it just contains statements.
SIMPLE STATEMENT
A simple statement lies entirely within a logical line. You do not need to place more than one
statement on a single logical line, with a semicolon (;) as the separator. Python recommends
one statement per line and makes programs more readable.
COMPOUND STATEMENT
A compound statement contains one or more statements and controls their execution. A
compound statement has one or more clauses, aligned at the same indentation. Each clause
has a header starting with a keyword and ending with a colon (:), followed by a body, which is
a sequence of one or more statements. When the body contains multiple statements, also
known as a block, these statements are on separate logical lines after the header line,
indented four spaces rightward. The block ends when the indentation returns to that of the
clause header.
PM PUBLISHERS PVT. LTD.
PMP
Data Types
Data types are used to define the type of value a data can contain. Data values in Python are
known as objects and each object has a type. A type of object determines which operations
the object supports. Data types define the way to store the values in memory.
Python has built-in data types such as numbers, strings, tuples, lists, dictionaries, and sets.
Some of them are discussed in this chapter. You can also create user-defined types, known as
classes. Data Types are of two types:
NUMBERS
The built-in numeric types in Python include integers numbers, floating-point numbers, and
complex numbers.
Integer/Long
Integers are the whole numbers consisting of + or – sign without decimal digits such as 1000, -
88, etc. Range of an integer in Python can be from -2147483648 to 2147483647.
Long integer has unlimited range subject to available memory. The long integer value is
handled by Python automatically. The long integer value can be appended L with value.
Example: >>> a=12 # This is an integer value
138 # This is a long integer value
>>> b=4324L
Float
Float data type represents floating point numbers which contain decimal point. For example,
0.5, -4.567, 0.001, etc. are called floating point numbers.
These numbers can also be written in scientific notation by using 'e' or 'E' to represent the
power of 10. Here 'e' or 'E' represents exponentiation.
Example: 4.6×10⁵ is written as 4.6E5. # This is a floating point value
Complex
A complex number is a number that is written in the form of a+bj or a+bJ. Here 'a' represents
the real part of the number and 'b' represents imaginary part of the number. The suffix 'j' or
'J' indicates square value of -1. The real and imaginary part may contain integers or floats.
Example: >>> c=4+5j # This is a complex value
SEQUENCE
A sequence is an ordered collection of items, indexed by positive integers. The three types of
sequence data type available in Python are; Strings, Lists and Tuples.
PMP
String
String is a sequence of characters used to store and represent text-based information. Single
and double quotes are used to represent strings in Python.
Example: >>> name="reema" # name stores a string value
Lists
List contains the list of elements separated by comma and enclosed within square brackets
([ ]). For example,
Example: >>> list= [10, 20, "abc”] # creates list with different types of elements
Tuple
Tuple is similar to the list. It contains a group of elements that can be of different types. The IT PLANET - 8 (UBUNTU 18.04)
elements in the tuple are separated by comma and enclosed in parentheses ().
Example: >>> tuple1=(10, 20, "abc") # creates tuple with different types of elements
Variables 139
Variables are used to store data in the memory. The data can be numbers, text and objects.
The data is given a name, so that it can be re-called whenever it is needed. Python program
needs that data stored in the memory to do its job.
Another way of looking at a variable is that it is like a label for something.
For example, to create a variable named rose, we use an equal to sign (=) and then tell Python
what information the variable should be the label for.
Here, we create the variable rose and tell Python that it labels the number 100:
>>> rose = 100 # here we say that rose labels the number 100
To find out what value a variable labels, enter print in the shell, followed by the variable name in
parentheses, like this:
>>> print(rose) # here we ask what rose is labeling
100 # here Python prints the result
We can also use more than one variable for the same item:
>>> rose = 100
>>> flower = rose
>>> print(flower)
100
In this example, we’re telling Python that we want the variable flower to label the same thing as
rose by using the equal sign between flower and rose.
So, now, rose is not a very useful name for a variable because it most likely doesn’t tell us
anything about what the variable is used for.
You can also write variables like total_marks:
>>> total_marks = 500
>>> print(total_marks)
PM PUBLISHERS PVT. LTD.
500
PMPThis example shows that we’re talking about 500 marks.
Variable names can be made up of letters, numbers, and the underscore character (_), but they
cannot start with a number. It also cannot use a reserved word.
Defining Input and Output in Python
A program needs to interact with user to complete a desired task which is done through Input-
Output facility. Input refers to the data entered by the user of program. Python provides built
in functions for defining input and output. Some of the functions like input () and print () are
used for standard input and output operations in Python.
The syntax of these functions are as follows:
INPUT IN PYTHON USING INPUT ( ) FUNCTION
The syntax and example of input() function is:
Syntax: input([prompt]), where prompt is the string you want to display.
Example: >>> num=(input("enter a number:"))
enter a number:23
>>> num
'23' #entered value 23 is a string, not a number
To convert this into a number we can use int() or float() functions.
Example: >>> int('23')
23 #entered value 23 is a number, not a string
>>> float('23')
140 23.0 #entered value 23.0 is a float
OUTPUT IN PYTHON USING PRINT( ) FUNCTION
The syntax and example of print() function is as follows:
Syntax: print (expression/constant/variable)
Print evaluates the expression before printing it on the monitor. Print statement outputs an
entire (complete) line and then goes to next line for subsequent output(s).
To print more than one item on a single line, comma (,) may be used.
Example 1: >>> print ("hello")
hello
Example 2: >>> print (3+5)
8
Example 3: >>> print (6*7)
42
Example 4: >>> print ("class 8 student")
class 8 student
Error Handling in PythonPMP
Python is an interpreted language which executes the code line by line at a time after
checking the errors. An error is a bug that prevents a program from executing in correct
manner. This makes the debugging process easier.
A Python program mainly contains following types of errors:
Syntax Errors
Every programming language in computer has certain rules and regulations. Syntax error will
occur when these rules and regulations of computer language are violated.
Example: >>> Print ("hello")
Syntax Error: invalid syntax # type print in lower case for correct result
>>> print ("hello")
hello IT PLANET - 8 (UBUNTU 18.04)
Logical Errors
These errors are also known as semantic errors. They cause the program to behave incorrectly,
but they do not usually crash the program.
Example: x = float(input('Enter a number: '))
y = float(input('Enter a number: '))
z = x+y/2
Logical Error: invalid logic # put x+y in braces as (x+y) for correct result
z = (x+y)/2
141
Programs in Python
Let's go through some simple Python programs to understand this interesting and powerful
language properly. Write the program in Script mode (Python shell).
Program 1: To take two integers as input and find their sum.
Source code in Script Mode
PM PUBLISHERS PVT. LTD. Output in Interactive mode
PMP
Program 2: To take length and width of a rectangle as input, and find its perimeter and area.
Source code in Script Mode
142
Output in Interactive mode
Self-Evaluation CHECKLIST
After reading the chapter, I know these points:
$ I know that Python is an interpreted and high level programming language.
$ I know that Interactive and script are two modes of programming in Python.
$ I know that Data Types define the way we use storage in the programs we write.
$ I know that tuple, range, list are the Data Types of Python.
$ I know that Interpreter is used for translating and executing the code line by line.
$ I know that input() function is used for taking inputs from users.
$ I know that print() function produces the output on the screen.
PMP
AgreeExercises
Disagree
A. Tick [ü] the correct answer.
1. ........................... is high level, structured, open source programming language.
a. Python b. Logo c. Qbasic
2. Python was founded by Guido Van Rossum in early ........................... .
a. 1970s b. 1980s c. 1990s
3. Python is an ........................... language which executes the code line by line at a time.
a. Compiled b. Runtime c. Interpreted
4. ........................... is a set of valid characters that a language can recognize.
a. Character Set b. Token c Variable
5. The values operated by the operator are called ........................... .
a. Constants b. Operands c Delimiters
B. Write ‘T’ for True and ‘F’ for False statements.
1. Python is named after “Python's Flying Circus”, a comedy program.
2. Python can run equally on different platforms such as Windows, Linux, Unix IT PLANET - 8 (UBUNTU 18.04)
and Macintosh.
3. The Shell mode is best for small programs and for the beginners.
4. .py is the extension of a python program.
5. Python is not a case sensitive language.
C. Fill in the blanks.
1. The ........................... mode screen shows the welcome message with version details.
2. Python uses ........................... to express the block structure of a program.
3. ........................... are the reserved words in Python and cannot be used as constant or
variable or any other identifier names.
4. ....................... are the data items which never change their value throughout program run.
5. A ........................... is an ordered collection of items, indexed by positive integers. 143
D. Define the following.
E.
1. Programming Language: ............................................................................................................
F.
144 ....................................................................................................................................................
2. Character Set: ...........................................................................................................................
....................................................................................................................................................
3. Token : .......................................................................................................................................
....................................................................................................................................................
4. Operator: ...................................................................................................................................
....................................................................................................................................................
5. Interpreter: ................................................................................................................................
....................................................................................................................................................
Differentiate between the following.
1. Interactive mode Script mode
................................................................. .................................................................
................................................................ .................................................................
................................................................ .................................................................
PM PUBLISHERS PVT. LTD.2. Relational Operators Assignment Operators
PMP..................................................................................................................................
................................................................ .................................................................
................................................................ .................................................................
3. Simple Statement Compound Statement
................................................................. .................................................................
................................................................ .................................................................
................................................................ .................................................................
4. Syntax Error Logical Error
................................................................. .................................................................
................................................................ .................................................................
................................................................ .................................................................
Answer in 1-2 sentences.
1. Who developed Python and when?
.....................................................................................................................................................
.....................................................................................................................................................
2. What do you mean by Data Type?
.....................................................................................................................................................
.....................................................................................................................................................
3. What is Input function? Write its syntax.
.....................................................................................................................................................
....................................................................................................................................................
4. What is Output function? Write its syntax.
.....................................................................................................................................................
....................................................................................................................................................
G. Answer Briefly.
1. What are the features of Python?
.....................................................................................................................................................
.....................................................................................................................................................
.....................................................................................................................................................
2. What is operator precedence? Explain with example.
.....................................................................................................................................................
.....................................................................................................................................................
.....................................................................................................................................................
3. How many Data Types are used in Python? Explain any one of them.
.....................................................................................................................................................
.....................................................................................................................................................
.....................................................................................................................................................
4. What is a variable? How can variables be declared?
.....................................................................................................................................................
.....................................................................................................................................................
.....................................................................................................................................................
5. What are the various types of errors in Python?
.....................................................................................................................................................
.....................................................................................................................................................
.....................................................................................................................................................
H. Application Based Question.
Riya has written a program in Python in which she has used input function for giving input the
value of a variable. After executing the program that value is a string, not a number. She wants
to convert this string into a number. By which function she can do so?
...........................................................................................................................................................
...........................................................................................................................................................
PMP
Activity Section
Lab Activity IT PLANET - 8 (UBUNTU 18.04)
A. Perform the following on Python IDLE.
1. 5+(3*4) .......................................................
2. (12/3) + 4 .......................................................
3. 3+4*6 .......................................................
4. 8+3*10 .......................................................
5. (8+3)*10 .......................................................
B. What will be the output of the following code:
a = 3 - 4 + 10
b=5*6
c = 7.0/8.0
print "These are the values:", a, b, c 145
.........................................................................................................................................................
C. Write the following program in Python to find the perimeter and semi-
perimeter of a triangle.
# Program to find the perimeter and semi-perimeter of a Triangle
a = float(input('Please Enter the First side of the Triangle: '))
b = float(input('Please Enter the Second side of the Triangle: '))
c = float(input('Please Enter the Third side of the Triangle: '))
Perimeter = a + b + c
s = (a + b + c) / 2
print("\n The Perimeter of Triangle = %.2f" %Perimeter);
print(" The Semi Perimeter of Triangle = %.2f" %s);
Discover More
Raspberry Pi PM PUBLISHERS PVT. LTD. Raspberry Pi
The Raspberry Pi is a low cost, credit-card sized computer, PMP
developed in the United Kingdom by the Raspberry Pi
Foundation to promote the teaching of basic computer
science in schools in developing countries. The objective of
Raspberry Pi, being used by kids all over the world, is to learn
to program and understand how computers work.
Raspberry Pi plugs into a computer monitor or TV, and uses a
standard keyboard and mouse. It is a little device that enables
people to explore computing and to learn how to program in
languages like Scratch and Python. It is capable of doing
everything you'd expect a desktop computer to do, from
browsing the Internet and play high-definition video to making
spreadsheets, word-processing, and playing games. The
Raspberry Pi 3 is the latest version of the Raspberry Pi.
HOW DO I GET STARTED WITH THE RASPBERRY PI 3?
Raspberry Pi itself is just a small board. You'll also need a
power supply, a monitor or TV, a HDMI cable to connect the
monitor, a mouse and a keyboard.
Once you've plugged in all the cables, the easiest way for new
users to run the Pi is to download the NOOBS (New Out-of-Box
Software) installer. Once the download is complete, follow the
instructions to install an Operating System (Raspbian) on the Pi.
The look and feel of Raspbian is like any desktop computer. The
OS, which is constantly being improved, recently had a
graphical overhaul and includes an optimized web browser, an
office suite, programming tools, educational games, and other
146 softwares.
10 Python - Control Structures
Topics Covered
•Control Structures •Conditional Control Structures •Loop Control Structures •Break Statement
•Continue Statement
Control Structures
A program is the set of instructions which are executed in sequential manner. In some
situations, we have to change the order of execution of the program based on conditions or
repetition of statements until conditions are met. Therefore, control statements are used to
control or change the flow of execution. Three basic control structures are:
1. Sequential 2. Conditional 3. Loop.
Sequential Control Structure: A sequential control structure shows one or more actions
following each other in order. Actions include input, process, and output. All actions must be
executed, that is, none can be skipped. Examples of actions are calculating totals and printing
them. The programs you have learnt in previous chapter have followed this control structure.
PMP
Conditional Control Structure: A conditional control structure tells the program which action
to take, based on a certain condition.
Loop Control Structure: The loop control structure enables a program to perform one or more
actions repeatedly as long as a certain condition is met.
INDENTATION IN PYTHON
Python programs get structured through indentation, i.e. code blocks
are defined by their indentation. All the statements in conditional
and looping statements are structured using indentation rather than
using curly braces ({}).
This principle makes it easier to read and understand other people's IT PLANET - 8 (UBUNTU 18.04)
Python code. Leading whitespace (spaces and tabs) at the beginning
of a logical line is used to compute the indentation level of the line,
which in turn is used to determine the grouping of statements.
Conditional Control Structures 147
We have a number of situations, where we may have to change the order of execution of
statements based on certain conditions. This involves a kind of decision-making to see whether
a particular condition has occurred or not, and then direct the computer to execute certain
statements accordingly.
When a program breaks the sequential flow and jumps to another part of the code, it is called
branching. When the branching is based on a particular condition, it is known as conditional
branching. If branching takes place without any decision, it is known as unconditional branching.
Python language possesses such decision-making capabilities and supports the following
statements known as control or decision-making statements to implement branching. For
example, if, if-else, nested if, elif, looping, etc.
THE IF STATEMENT
The if statement is a powerful decision-making statement and is used to control the flow of
execution of statements. This statement is used to execute one or more statements depending
on whether a condition is True or not.
Syntax: condition False
if condition: True
statements
First the condition is tested, if the condition is true then statements Body of if
after colon (:) are executed.
Example 1:
“Are you older than 50?” and if the answer is yes, respond with “You are too old!”
>>> age = 53 Output
>>> if age > 50: You are too old!
print(”You are too old!”)
An if statement is made up of the if keyword, followed by a condition and a colon (:), as in
if age > 50:. The lines following the colon must be in a block, and if the answer to the question
is yes, the commands in the block will run.
PM PUBLISHERS PVT. LTD.
Print Group of Programming Statements
PMP
If the answer to the question is yes, then you can print a group of programming statements
under if block.
Example 2:
THE IF-ELSE STATEMENT
The if...else statement is an extension of the simple if statement.
Syntax:
if test expression: condition False
Body of if
else: True
Body of else Body of if Body of else
The if..else statement evaluates test expression and will execute
body of if only when test condition is True. If the condition is False,
148 body of else is executed. Indentation is used to separate the blocks.
Example: Output
enter any number: 8
num = int(input("enter any number: ")) Positive or Zero
if num >= 0:
print("Positive or Zero")
else:
print("Negative number")
In the above example, if value of num is greater than or equal to zero then statement in if block
will be executed; otherwise if the value of num is less than zero then statement in else block
will be executed.
IF-ELIF-ELSE STATEMENT
When multipath decisions are involved, we can put ifs Test False
together. A multipath decision is a chain of ifs in which Expression
the statement associated with each else is an if or elif.
of if
Syntax: True Test False
Expression
if test expression: Body of if
Body of if of elif
True
PMPelif test expression: Body of elif Body of else
Body of elif
else:
Body of else
If the condition for if statement is False, it checks the condition of the next elif block and so on.
If all the conditions are False, body of else is executed. Only one block among the several
if...elif...else blocks is executed according to the condition. The if block can have only one else
block. But it can have multiple elif blocks.
Example :
marks = int (input("Enter your marks: "))
if marks > 90:
print("Execellent")
elif marks > 75: IT PLANET - 8 (UBUNTU 18.04)
print("Very Good") Output
elif marks > 60: Enter your marks: 78
Very Good
print("Good")
elif marks > 50:
print("Need to work harder")
else:
print("Poor, work very hard to score good marks")
In the above example, if the marks are greater than 90 then statement in if statement will be 149
executed, if the marks are greater than 75 then statement in elif will be printed, if the marks
are greater than 60 then statement in elif will be printed, if the marks are greater than 50 then
statement in elif will be printed, otherwise if the value of marks are less than 50, statement in
else will be executed.
NESTED IF STATEMENT condition-1 True
Nesting is the process of placing the if or if-else or False condition-2
elif statement in another statement. It enables us to
make complex decisions based on different inputs. False True
Syntax:
Statement-3 Statement-2 Statement-1
if condition:
if condition: Statement-n
statements
else:
statements
else:
statements
The logic of execution is, if the condition-1 is false, the statement-3 will be executed; otherwise
it continues to perform the second test. If the condition-2 is true, the statement-1 will be
evaluated; otherwise the statement-2 will be evaluated, and then the control is transferred to
the statement-n.
Example :
num1 = int (input("Enter First Number: "))
num2 = int (input("Enter Second Number: "))
num3 = int (input("Enter Third Number: "))
if num1 > num2:
if num1 > num3:
print (“Num1 is greatest:”, num1)
else:
print (“Num3 is greatest:”, num3)
else:
if num2 > num3:
print (“Num2 is greatest:”, num2)
else:
print (“Num3 is greatest:”, num3)
PM PUBLISHERS PVT. LTD. Output
Enter First Number: 6
PMP Enter Second Number: 64
Enter Third Number: 33
Num2 is greatest: 64
Loop Control Structures
Nothing is boring than having to do the same thing again and again. In programming,
programmers do not particularly like repeating the same commands. Thankfully, most
programming languages have loop option for that problem.
Loops cause a section of your program to be repeated a certain number of times. The repetition
continues while a condition is true. When the condition becomes false, the loop ends, and the
control passes to the statements following the loop. In looping, a sequence of statements is
executed until some conditions for the termination of the loop are satisfied. A program loop
therefore consists of two segments, one known as body of the loop and the other known as the
150 control statement. The control statement tests certain conditions and then directs the repeated
execution of the statements contained in the body of the loop.