KnowledgeBoat Logo
|
OPEN IN APP

Part II: AI — Chapter 3.1

Familiarisation with Python

Class 9 - Exploring Robotics & AI



Multiple Choice Questions

Question 1

Which of the following programming languages is depicted by the given clip?

Which of the following programming languages is depicted by the given clip. Familiarisation with Python, APC ICSE Robotics & Artificial Intelligence Solutions Class 9.
  1. Java
  2. C++
  3. Python
  4. Ruby

Answer

Python

Reason — The picture depicts the official logo of Python programming language, which consists of two intertwined snakes in blue and yellow colours.

Question 2

In Object Oriented Programming, the emphasis is laid on ...............

  1. procedure
  2. methods
  3. class
  4. data

Answer

data

Reason — In Object Oriented Programming, the emphasis is put on the data values rather than functions. The data values are confined and used within the stipulated programming area to encourage data security.

Question 3

............... is known as creator of Python.

  1. Guido van Rossum
  2. John Kemeny
  3. James Gosling
  4. Thomas Kurtz

Answer

Guido van Rossum

Reason — Guido van Rossum, who holds a Master's degree in Mathematics and Computer Science from the University of Amsterdam, Netherland, is regarded as the creator of Python. He named his project 'Python' in the year 1991.

Question 4

In Python, ............... mode is used to write a program file.

  1. Interactive
  2. Interaction
  3. Script
  4. Text

Answer

Script

Reason — Script mode is used only when the user needs to create a program file. In this mode, the user can save the complete set of instructions in a program file.

Question 5

In which language is Python written?

  1. English
  2. C
  3. PHP
  4. All of them

Answer

C

Reason — Python is a general-purpose interpreted, interactive high-level programming language written in C programming language.

Question 6

All keywords in Python are defined in ...............

  1. uppercase letters
  2. lowercase letters
  3. toggle case
  4. None of them

Answer

lowercase letters

Reason — In Python, all the keywords (except True, False and None) are in lowercase and they must be written as it is, since Python is a case-sensitive language.

Question 7

Which of the following is not a Python keyword?

  1. true
  2. false
  3. right
  4. not

Answer

right

Reason — The words 'true', 'false' and 'not' are reserved keywords in Python which carry special meaning for the language translator. However, 'right' is not a Python keyword and can be used as an identifier.

Question 8

Which is the default Python command prompt?

  1. <<<
  2. <<
  3. >>>>
  4. >>>

Answer

>>>

Reason — The default Python command prompt is represented by three greater-than signs (>>>). It appears in the interactive mode where the user can type a statement and instantly obtain the output.

Fill blanks

Question 1

Fill in the blanks:

  1. Python language is ............... oriented programming language.
  2. An ............... may be a function name, a class name or a variable name.
  3. ............... is a 3D game engine which enables the users to develop interactive games.
  4. Python is a ............... generation programming language.
  5. Escape sequences are some ............... characters which are used as commands in programs.
  6. Python has come from BBC's popular TV show Monty Python's ...............

Answer

  1. Python language is object oriented programming language.
  2. An identifier may be a function name, a class name or a variable name.
  3. PySoy is a 3D game engine which enables the users to develop interactive games.
  4. Python is a fourth generation programming language.
  5. Escape sequences are some non-graphic characters which are used as commands in programs.
  6. Python has come from BBC's popular TV show Monty Python's Flying Circus.

Evaluate the following expressions

Question 1

Evaluate the following expressions:

Given: a=5; b=4

  1. 12*(a+b)-10
  2. 12*a+b-10
  3. 12+a*b-10
  4. 12-10+a*b

Answer

  1. 12*(a+b)-10
    = 12*(5+4)-10
    = 12*9-10
    = 108-10
    = 98

  2. 12*a+b-10
    = 12*5+4-10
    = 60+4-10
    = 64-10
    = 54

  3. 12+a*b-10
    = 12+5*4-10
    = 12+20-10
    = 32-10
    = 22

  4. 12-10+a*b
    = 12-10+5*4
    = 12-10+20
    = 2+20
    = 22

Write down the escape sequences

Question 1

Write down the escape sequences for the following:

DescriptionEscape Sequences
Horizontal tab
Backslash
Single quote
Double quote
Backspace
New line feed

Answer

DescriptionEscape Sequences
Horizontal tab\t
Backslash\
Single quote'
Double quote"
Backspace\b
New line feed\n

Assertion and Reason based question

Question 1

Assertion (A): Python works in two different modes. These modes are used as per the need of the user while performing the tasks.

Reason (R): Interactive mode refers to the mode where the user is able to see the instant output for the given input. Whereas, the script mode is used only when the user needs to make a program file.

Based on the above discussion, choose an appropriate statement from the options given below:

  1. Both A and R are true and R is the correct explanation of A.
  2. Both A and R are true and R is not the correct explanation of A.
  3. A is true but R is false.
  4. A is false but R is true.
  5. Both A and R are false.

Answer

Both A and R are true and R is the correct explanation of A.

Reason — Python works in two different modes namely Interactive mode and Script mode. The interactive mode allows the user to obtain instant output by typing a command at the Python prompt (>>>) and pressing 'Enter'. The script mode allows the user to write and save a complete set of instructions as a program file. Hence, the reason correctly explains the assertion.

Application based question

Question 1

In Python programming, this mode refers to the mode where the user can instantly obtain the output, for the input given. The moment a statement or a command is typed in the Python command prompt and the 'Enter' key is pressed, the output will appear on the next line of the interactive screen.

Read the above paragraph to answer the following questions:

(a) Name the mode where get the instant output on the screen.

(b) Write down representation of the default Python prompt.

Answer

(a) Interactive Mode

(b) The default Python prompt is represented by >>> (three greater-than signs).

Write short notes

Question 1

Write short notes on Character Sets with reference to Python language.

Answer

Python is a computer language that enables the users to communicate with the computer system, using the set of valid characters that the language can recognise, similar to the alphabet of English language. It may be any letter, digit or any other symbol. The different character sets used in Python include Letters (A-Z and a-z), Digits (0-9), Arithmetical Operators (+, -, *, /, %), Logical Operators (and, or, not), Relational Operators (<, <=, >, >=, == and !=), Special Characters (space, backslash, underscore, parenthesis, etc.) and White Spaces (Blank space, Tab key, Enter key, Newline).

Question 2

Write short notes on Escape Sequences with reference to Python language.

Answer

Escape sequences are some non-graphic characters which are used as commands to direct the cursor while printing. These characters are frequently used in Python codes. An escape sequence character begins with a backslash (\) and it is followed by one or more characters. Some common escape sequences are \t (Horizontal tab), \ (Backslash), ' (Single quote), " (Double quote), \b (Backspace) and \n (New line feed).

Question 3

Write short notes on Literals with reference to Python language.

Answer

When we write a code, we may come across some quantities which remain fixed (i.e., do not change) throughout the execution of the program. Such quantities are termed as Literals or Constants. These constants include integer, string and boolean values. For example, 345, "Computer", True, etc. are some literals used in Python.

Question 4

Write short notes on Identifiers with reference to Python language.

Answer

An identifier is a component of a programming statement (token) defined with a name to identify a block (i.e., a set of indented statements). A function name, a class name or a variable name are also referred to as identifiers. For example, in the statement n = 25, n is a variable name which refers to a specific identifier. Since Python is case sensitive, Num and num are considered to be two different identifiers.

Question 5

Write short notes on Assignments with reference to Python language.

Answer

Assigning means to store values in variables using a token '=' which acts as an assignment operator. The operand to the left of '=' operator is the variable name and the operand to the right of '=' operator is the value to be stored. For example, n = 15 means that the numeric constant 15 is stored in the variable n.

Question 6

Write short notes on Keywords with reference to Python language.

Answer

Keywords are the reserved words which are preserved by the system and carry special meaning for the language translator (interpreter). These words cannot be used as variable names in the program. Some examples of Python keywords are False, class, else, return, None, continue, for, not, True, def, if, or, and, del, import, pass, break, elif, is, while, etc.

Question 7

Write short notes on Punctuators with reference to Python language.

Answer

Punctuators are the special signs used as special characters in Python to organise the structure as well as to put emphasis on the expressions of the sentences. For example, Comma (,), colon (:), semicolon (;), [ ], { }, ( ), # are some of the punctuators commonly used in Python coding.

Question 8

Write short notes on Python output statement.

Answer

In Python, the print() function is used to view the output of a program on a standard output device (i.e., monitor), when executed. The content within the round brackets of print() function may be a value, a variable, a message or the combination of message and variables. For example, print(25+15) will display 40 on the screen, and print("PYTHON") will display PYTHON on the screen.

Answer the following questions

Question 1

What is object-oriented programming? Name two object oriented programming languages.

Answer

Object-oriented programming (OOP) is an approach in which the emphasis is laid on data rather than functions. It allows the user to split the complete program into a number of segments called Objects. The data values of an object can only be used within the functions of the same object and are not directly accessible to other objects of the program. However, the objects can communicate with each other through functions. This encourages data security.

Two object-oriented programming languages are Java and C++.

Question 2

Name two different modes in Python that you can work on.

Answer

The two different modes in Python that we can work on are:

  1. Interactive Mode — In this mode, the user can instantly obtain the output for the input given at the Python command prompt (>>>).

  2. Script Mode — In this mode, the user can create a program file and save the complete set of instructions in it for later execution.

Question 3

What is meant by cross-platform language?

Answer

A cross-platform language refers to a programming language that is platform independent, which means a program developed using such a language can run on different operating systems. For example, if Python code has been developed in Windows then its library can also run on other platforms such as UNIX, LINUX, Macintosh, etc. Hence, Python is referred to as a cross-platform compatible language.

Question 4

Python is a case sensitive programming language. Comment.

Answer

Python is a case sensitive programming language, which means it differentiates between the uppercase and lowercase letters. In Python, the keywords are case sensitive and all the keywords (except True, False and None) are in lowercase and they must be written as it is. Python is also case sensitive when it deals with identifiers. For example, Num and num are considered to be two different identifiers in Python.

Question 5

What is meant by an interpreter? Name an interpreter based programming language.

Answer

An interpreter is a software that is used to convert a program written in a high-level language into its equivalent machine language. It accepts instructions and generates its machine codes line-by-line or statement-by-statement. The control does not move to the next line of statement until the previous one is corrected.

Python is an interpreter-based programming language.

Question 6

What are the advantages of Python as a programming language?

Answer

The advantages of Python as a programming language are as follows:

  1. It is known for its simplicity and readability that makes it an excellent choice for both beginners and experienced programmers.
  2. It is an interpreter-based language which allows easier debugging and code development.
  3. It is dynamically typed which means we do not need to declare the data types explicitly, making it flexible and reliable.
  4. It is known for platform independence which makes it portable across operating systems, allowing real-time code execution and testing.
  5. The syntax is quite concise that allows the developers to prototype applications quickly with less code.
  6. It supports both object-oriented and procedural programming, providing versatility in coding styles.
  7. It is used in IoT (Internet of Things) applications due to its simplicity and versatility.
  8. It provides extensive support libraries like NumPy for numerical calculations and Pandas for data analytics, making it suitable for scientific and data-related applications.

Question 7

Python is free and open source. What is meant by this statement?

Answer

The statement "Python is free and open source" means that Python can be freely downloaded and used without any cost. The users can freely distribute the copies of the software, read the source code, make changes in it and use it in new programs. Python is available for free download from the website https://www.python.org.

Question 8

How is Python useful for the following applications? Explain in brief.

(a) Game Development

(b) Artificial Intelligence

Answer

(a) Game Development — Like Java and C++, Python also has various modules that support the development of video and 3D games. For example, PySoy is a 3D game engine which enables the users to develop interactive games. Some popular games which have been built using Python are Disney's ToonTown Online, Vega Strike, etc.

(b) Artificial Intelligence — Artificial Intelligence is the technology that makes use of machines, like computer systems or robots, to think and learn like the human mind. This can be done by developing computer system and algorithms that are capable of learning from data, reasoning, understanding natural language, perceiving their environment and adapting to new situations. Python is widely used in Artificial Intelligence due to its simplicity, readability and the availability of extensive libraries.

PrevNext