KnowledgeBoat Logo
OPEN IN APP

Chapter 2

Getting Started with Python

Class 11 - Informatics Practices Preeti Arora



Fill in the Blanks

Question 1

Programs are the set of instructions given to a computer to perform a particular task.

Question 2

Python was developed by Guido Van Rossum.

Question 3

Python is called a/an interpreted language.

Question 4

Python is a/an case-sensitive language in terms of its syntax.

Question 5

In Python, a syntax error is detected by the interpreter at runtime.

Question 6

Python is a/an platform independent language.

Question 7

To start Python from the command prompt, use the python command.

Question 8

Python programs are saved using the .py or .pyw extension.

Question 9

Python programming can be done in interactive and script modes.

Question 10

Interactive mode does not save the commands entered by you in the form of a program.

Question 11

The shortcut key to run Python script is F5.

State True or False

Question 1

Python is a dynamically typed language.

Answer

True

Reason — Python is a dynamically typed language because variables do not need to be declared with a specific type. Instead, the type of a variable is determined at runtime based on the value assigned to it.

Question 2

Alt+R is used to repeat the last typed command in Python shell.

Answer

False

Reason — For repeating or recalling the last command in the Python shell, the correct key is the up arrow key (↑).

Question 3

Print and print are same in Python.

Answer

False

Reason — In Python, print and Print are not the same because Python is a case-sensitive language.

Question 4

The sep argument is used with print() method.

Answer

True

Reason — The sep argument in the print() function is used to specify a string that separates the objects being printed. The default separator is a space.

Question 5

Python is a compiled high-level language.

Answer

False

Reason — Python is an interpreted high-level language.

Question 6

Python is a cross-platform language.

Answer

True

Reason — Python is a cross-platform language because it can run on various operating systems, such as Windows, macOS, Linux, etc.

Question 7

Python is an interpreted language, not a compiled language.

Answer

True

Reason — Python is an interpreted language, not a compiled language. This means that Python code is executed line by line at runtime by an interpreter, without the need for a separate compilation step to machine code.

Question 8

Python is a free, open-source and portable language.

Answer

True

Reason — Python is free and open-source, meaning anyone can freely use, distribute, and modify it. It is also highly portable, running on various platforms such as Windows, macOS, Linux, and others.

Question 9

Python Editor refers to Script mode in Python.

Answer

True

Reason — Python Editor refers to a mode in IDLE where we can write and run Python scripts, also known as Script mode.

Question 10

Ctrl+Q shortcut key combination is used to exit Python.

Answer

True

Reason — Ctrl+Q shortcut key combination is used to exit Python.

Multiple Choice Questions

Question 1

Python was developed by ............... .

  1. Charles Babbage
  2. Guido van Rossum
  3. Tim Berners Lee
  4. Robert E. Kahn

Answer

Guido van Rossum

Reason — Python was developed by Guido van Rossum.

Question 2

Which of the following is syntactically correct text?

  1. "This is great!"
  2. 'she shouted 'HELLO' loudly'
  3. "Goodbye'
  4. "This "course" is good"

Answer

"This is great!"

Reason — The "This is great!" text uses double quotes (") to properly enclose the entire string. In Python, strings enclosed in either single quotes (') or double quotes (") are valid, but the entire string must be enclosed in the same type of quote. The other options have mismatched quotes, which cause syntax errors in Python.

Question 3

Python language is ............... .

  1. Free
  2. Open Source
  3. Free and Open Source
  4. Proprietary

Answer

Free and Open Source

Reason — Python is a free and open-source language.

Question 4

Identify the correct print() statement:

  1. print(Hello)
  2. print("Hello")
  3. print('Hello")
  4. print("Hello')

Answer

print("Hello")

Reason — In Python, when using the print() function, strings must be enclosed in matching pairs of either single (') or double quotes ("). Therefore, the correct statement is print("Hello").

Question 5

Which of the following is the shortcut key combination for exiting Python shell?

  1. F5
  2. Alt+F1
  3. Ctrl+E
  4. Ctrl+Q

Answer

Ctrl+Q

Reason — The shortcut key combination for exiting Python shell is Ctrl+Q.

Question 6

The extension for a Python file is given as:

  1. .pt
  2. .pwy
  3. .py or .pyw
  4. .yppy

Answer

.py or .pyw

Reason — The extension for a Python file is .py or .pyw.

Question 7

Python is a/an ............... language.

  1. Compiled
  2. Interpreted
  3. Compiled & Interpreted
  4. None of these

Answer

Interpreted

Reason — Python is an interpreted language. This means that Python code is executed line by line at runtime by an interpreter, without the need for a separate compilation step to machine code.

Question 8

The interactive interpreter of Python is termed as ............... .

  1. Python shell
  2. Python Script mode
  3. Python Editor mode
  4. Python command line

Answer

Python shell

Reason — The interactive interpreter of Python is termed as Python shell.

Question 9

The three greater than signs (>>>) are called the Python ............... .

  1. Cursor
  2. Command prompt
  3. Pointer
  4. Blinking cursor

Answer

Command prompt

Reason — The three greater than signs (>>>) are called the Python command prompt or interactive prompt.

Question 10

Single-line comments in Python begin with ............... symbol.

  1. %
  2. "
  3. '''
  4. #

Answer

#

Reason — The # symbol in Python indicates the start of a single-line comment, which extends from the # to the end of the line.

Question 11

Which of the following codes is correct?

1.

print("Programming is fun")
print("Python") 
print("Computer Science")

2.

print ("Programming is fun)
print("Python") 
print("Computer Science)

3.

Print("Programming is fun")
print("Python") 
print("Computer Science")

4.

Print("Programming is fun")
Print("Python") 
Print("Computer Science")

Answer

print("Programming is fun")
print("Python") 
print("Computer Science")

Reason — In Python, the print() function is written in lowercase (print) and strings must be enclosed in matching pairs of either single (') or double quotes ("). Therefore, the correct code would be :

print("Programming is fun")
print("Python") 
print("Computer Science")

Question 12

Python is a case-sensitive language. This means ............... .

  1. Capital and small letters are same for Python
  2. Python doesn't care about the case of alphabets
  3. Python treats capital and small letters as different
  4. Python automatically capitalizes the small letters

Answer

Python treats capital and small letters as different

Reason — Python is a case-sensitive language. This means that Python differentiates between capital and small alphabets.

Question 13

............... mode of Python gives instant result of typed statement.

  1. Interactive mode
  2. Script mode
  3. Both Interactive and Script mode
  4. None of these

Answer

Interactive mode

Reason — Interactive mode of Python gives instant result of typed statement.

Assertions and Reasons

Question 1

Assertion (A): Python is an object-oriented programming language.

Reasoning (R): Using Python, any software can be designed. Everything in Python is an object.

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

Answer

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

Explanation
Python is an object-oriented programming language, which means it supports the concepts of classes and objects. In Python, everything is treated as an object, including integers, strings, functions, and even modules and packages. Using Python, any software can be designed.

Question 2

Assertion (A): Python uses an interpreter to convert source code to object code.

Reasoning (R): Python interpreter is a special virtual engine that converts machine code to source code.

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

Answer

A is true but R is false.

Explanation
Python uses an interpreter to convert source code to object code. The Python interpreter is a special virtual engine that converts source code (written in Python) to machine code that can be executed by the computer.

Question 3

Assertion (A): To print the value of a variable, Python uses print() method.

Reasoning (R): print() method displays the content on the system screen or console.

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

Answer

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

Explanation
The print() function is a built-in function in Python that displays the content on the system screen or console. To print the value of a variable, Python uses the print() function.

Question 4

Assertion (A): Python is a cross-platform language.

Reasoning (R): Python code can run on a variety of platforms such as windows, Macintosh and Apple.

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

Answer

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

Explanation
Python is a cross-platform language because it can run on various operating systems, such as Windows, Macintosh, Apple, Linux etc.

Question 5

Assertion (A): Python is a dynamically typed language.

Reasoning (R): Python interpreter assigns variables a data type at runtime based on the variable's value at that time.

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

Answer

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

Explanation
Python is a dynamically typed language because variables do not need to be declared with a specific type. Instead, the type of a variable is determined at runtime based on the value assigned to it.

Question 6

Assertion (A): Python is the fastest language.

Reasoning (R): Python is an interpreted language.

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

Answer

A is false but R is true.

Explanation
Python is not considered the fastest programming language as it is slower than many compiled languages such as C or C++ because it is interpreted rather than compiled. Python is an interpreted language, which means that Python code is executed line by line at runtime by an interpreter, without the need for a separate compilation step to machine code.

Question 7

Assertion (A): Python IDLE or Interpreter provides two modes to work with, create and run the scripts or code.

Reasoning (R): Interactive mode comprises Python prompt '>>>' where you can simply start typing the command and display output, and script window, where you can write Python program in a file and execute it to display output.

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

Answer

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

Explanation
Python's Integrated Development and Learning Environment (IDLE) or interpreter provides two modes to work with: interactive mode and script mode. Interactive mode comprises the Python prompt '>>>' where we can start typing commands and see the output immediately. In script mode, we can write a Python program in a file and execute it to display the output.

Question 8

Assertion (A): Python is a general-purpose language, meaning it can be used to create a variety of different programs.

Reasoning (R): Python is used to build websites and software, automate tasks and conduct data analysis.

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

Answer

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

Explanation
Python is a general-purpose language, meaning it is versatile and can be used to create a variety of programs. Python is an object-oriented language used to build websites and software, automate tasks, and conduct data analysis.

Solutions to Unsolved Questions

Question 1

When was Python introduced?

Answer

Python was developed in February 1991.

Question 2

Who developed Python and which two languages contributed to Python as a programming language?

Answer

Guido Van Rossum is the developer of Python. ABC language and Modula-3 contributed to Python as a programming language.

Question 3

Python is free and open-source. What do you understand by this feature?

Answer

Python is free and open-source means that it is available to anyone at no cost, and its source code can be freely accessed, modified, and distributed by anyone.

Question 4

Is Python case-sensitive?

Answer

Yes, Python is a case-sensitive language. This means that Python differentiates between uppercase (capital) and lowercase (small) letters.

Question 5

What is IDLE?

Answer

IDLE is a simple Integrated Development and Learning Environment that comes with Python. The most important feature of IDLE is that it is a program that allows the user to edit, run, browse and debug a Python program from a single interface.

Question 6

Differentiate between displaying and printing method in Python.

Answer

Printing in Python refers to using the print() function to output information to the console. The print() function takes one or more arguments, converts each argument to a string (if necessary), and displays them as text. On the other hand, displaying can be a more general term that encompasses presenting information or output in various forms, not limited to just text output in the console.

Question 7

Briefly explain the salient features of Python.

Answer

The salient features of Python are as follows:

  1. Python is an interpreted, interactive, directly executed language with a pre-compiled code. This means that it is processed at runtime by the interpreter and we need not compile our program before executing it.
  2. It is a loosely type object-oriented programming language with a few keywords, simple English-like structure and is easy to learn.
  3. It is a free, open-source and portable language having a large repository of libraries.
  4. It takes less time to develop as Python programs are typically 3 to 5 times shorter than the equivalent programming languages. This is because of its built-in, high-level data types and its dynamic typing.
  5. It is extensible/extendable and highly efficient as there is no wastage of time in declaring the types of variables or arguments.
  6. It supports GUI (Graphical User Interface) and garbage collection (better memory management).
  7. It is easily compatible with other languages like C, C++, Core Java etc.
  8. Python is used for both scientific and non-scientific programming.

Question 8

What do you understand by cross-platform software with respect to Python?

Answer

Python is platform-independent and a cross-platform language because it can run on various operating systems, such as Windows, macOS, Linux etc.

Question 9

What are the advantages of Python programming language?

Answer

Advantages of Python programming language are:

  1. Easy to Use — Python is compact, programmer-friendly and very easy to use object oriented language with very simple syntax rules.
  2. Expressive Language — Python is an expressive language, it takes fewer lines of codes to represent the same syntax.
  3. Interpreted Language — Python is an interpreted language, not a compiled language. It makes Python an easy-to-debug language and thus suitable for beginners to advanced users.
  4. Completeness — Python has a rich standard library that provides modules for most types of required functionality like emails, web-pages, databases, GUI development, network connections, etc.
  5. Cross-platform Language — Python can run equally well on variety of platforms — Windows, Linux/UNIX, Macintosh, supercomputers, smart phones, etc.
  6. Free and Open Source — Python language is freely available along with its source-code.
  7. Variety of Usage/Applications — Python has evolved into a powerful, complete and useful language over these years. These days Python is being used in many diverse fields/applications, some of which are Scripting, Web Applications, Game development, Database Applications, System Administrations, Rapid Prototyping, GUI Programs.

Question 10

In how many different ways can you work in Python?

Answer

We can work in Python in two ways:

  1. Interactive mode (also called Immediate mode)
  2. Script mode

Question 11

What are the advantages/disadvantages of working in Interactive mode in Python?

Answer

Interactive mode is useful for testing code. We can type the commands one by one and get the result of error immediately for each command. Disadvantages of Interactive mode are that it does not save commands in form of a program and also output is sandwiched between commands.

Question 12

Write some limitations of Python.

Answer

Some limitations of Python programming language are:

  1. Not the Fastest Language — As Python is an interpreted language so its execution-times are not that fast compared to some compiled languages.
  2. Lesser Libraries than C, Java, Perl — Library collection of C, Java, Perl is better than Python.
  3. Not strong on Type-Binding — Python interpreter is not very strong on catching 'Type-Mismatch' issues.
  4. Not easily convertible — Translating Python programs to other languages is difficult due to its lack of syntax.

Question 13

What is the difference between Script mode and Interactive mode in Python?

Answer

In script mode, we write a Python program in a file and execute it to display the output and in interactive mode, we use the Python prompt '>>>' to start typing commands and see immediate output.

Question 14

Write instructions to the Interactive mode for the following:

(a) To display sum of 3, 8.0, 6 * 12

(b) To print sum of 16, 5.0, 44.0

Answer

(a)

>>> 3 + 8.0 + 6 * 12

(b)

>>> print(16 + 5.0 + 44.0)

Question 15

Write the output of the following:

num1 = 4 
num2 = num1 + 1 
num1 = 2
print(num1, num2)

Answer

Output
2 5
Explanation

In the above code, num1 is initially assigned the value 4. Then, num2 is set to num1 + 1, resulting in num2 being 5. Subsequently, num1 is reassigned the value 2, changing its original value from 4 to 2. When print(num1, num2) is executed, it displays the current values of num1 and num2, which are 2 and 5, respectively.

Question 16

Consider the statements given below and write Python command to display these statements in both Interactive and Script mode.

Python is easy to learn and write.
It allows us to work in two modes: Interactive mode and Script mode.
Interactive mode is also known as Python Shell and Script mode is also known as Python Editor.
It is a platform-independent language.
We find it interesting to work with Python.

Answer

Interactive Mode:

>>> print("Python is easy to learn and write.")
>>> print("It allows us to work in two modes: Interactive mode and Script mode.")
>>> print("Interactive mode is also known as Python Shell and Script mode is also known as Python Editor.")
>>> print("It is a platform-independent language.")
>>> print("We find it interesting to work with Python.")

Script Mode:

print("Python is easy to learn and write.")
print("It allows us to work in two modes: Interactive mode and Script mode.")
print("Interactive mode is also known as Python Shell and Script mode is also known as Python Editor.")
print("It is a platform-independent language.")
print("We find it interesting to work with Python.")

Question 17

Write a code that prints your full name and your birthday as separate strings.

Answer

full_name = "Jeevika Sharma"
birthday = "January 17, 2000"

print("Full Name:", full_name)
print("Birthday:", birthday)
Output
Full Name: Jeevika Sharma
Birthday: January 17, 2000

Question 18

Record what happens when the following statements are executed:

(a) print (n = 17)

(b) print (8+9)

(c) print (4.2, "hello", 6-2, "world", 15/2.0)

Answer

(a) It raises TypeError as 'n' is an invalid keyword argument for print() function.

(b) 17

(c) 4.2 hello 4 world 7.5

Question 19

Use IDLE to calculate:

(a) 6+4*10

(b) (6+4) *10

Answer

(a) 46

(b) 100

Question 20

Try the following code on the Python shell and evaluate the output generated:

>>> print (3.14159*7)
>>> print('I am a class XI' + 'student')
>>> print('I', 'am')
>>> print ("class XI student")
>>> print ("I'm", 16, "years old")

Answer

Output
21.99113
I am a class XIstudent
I am
class XI student
I'm 16 years old
PrevNext