These Class 9 AI Important Questions Chapter 5 Introduction to Python Class 9 Important Questions and Answers NCERT Solutions Pdf help in building a strong foundation in artificial intelligence.
Introduction to Python Class 9 Important Questions
Class 9 AI Introduction to Python Important Questions
Important Questions of Introduction to Python Class 9 – Class 9 Introduction to Python Important Questions
Introduction to Python Class 9 Very Short Answer Type Questions
Question 1.
What is Python?
Answer:
Python is a high-level, interpreted programming language known for its readability and simplicity.
Question 2.
When was Python first released?
Answer:
In 1991.
Question 3.
What is a variable in Python?
Answer:
A variable is a named location used to store data in memory.
Question 4.
How do you write a comment in Python?
Answer:
Using the ‘#’ symbol
Question 5.
What is the extension of Python files?
Answer:
‘.py’
Question 6.
How do you print something to the console in Python?
Answer:
Using the ‘print()’ function.
Question 7.
What is a list in Python?
Answer:
A list is a collection of items in a particular order.
Question 8.
What is a dictionary in Python?
Answer:
A dictionary is a collection of key-value pairs.
Question 9.
What is a loop in Python?
Answer:
A loop is a sequence of instructions that is continually repeated until a certain condition is reached.
Question 10.
Name the two types of loops in Python
Answer:
‘for’ loop and ‘while’ loop
Question 11.
How do you handle exceptions in Python?
Answer:
Using the ‘try’ and ‘except’ blocks.
Question 12.
What is a program?
Answer:
The step-by-step instruction written in any programming language to do a specific task is known as a program. A program is written in any programming language which the computer can understand and execute.
Question 13.
What is the use of an arrow in flowchart?
Answer:
It manages the flow of instructions within a flowehart.
Question 14.
Define the steps involved in Computer problem solving.
Answer:
- Understanding the problem
- Analysing the problem
- Developing the solution
- Coding and implementation
Question 15.
What is CodeCombat?
Answer:
CodeCombat is a no-cost educational coding game that makes learning JavaScript or Python coding enjoyable. It is accessible to all age groups to meet the demands of students studying computer science and coding at all levels.
Question 16.
What is the use of if statement in Python?
Answer:
It executes the set of statements based on a condition.
Question 17.
What does the pop() function do?
Answer:
The pop() method returns the deleted value after removing an element from the list depending on the function’s provided index number.
Question 18.
Explain the use of + operator?
Answer:
The + operator is used to concatenate the list with another list.
Question 19.
Name different modes of working in Python.
Answer:
Below are the different modes of working in Python are:
- Interactive mode
- Script mode
Question 20.
How do you import a module in Python?
Answer:
Using the ‘import’ statement e.g. ‘import math’.
Introduction to Python Class 9 Short Answer Type Questions
Question 1.
Identify the data types of the values given below:
6,6 j, 15 . 0,” 16′,’ ” 16′, 2+o j,, 16
Solution :
6-Integer
6j-Complex number
15.0-Floating-point number
“16”-String
“16”-String
2+oj-Complex number
16-Integer
Question 2.
What will be the output produced by these?
(a) 15/3
(b) 16/16
(c) 14%4
(d) 18.0/6
(e) 14.0/4
(f) 14.0%4
Solution :
(a) 5.0
(b) 1
(c) 2
(d) 3
(e) 3.0
(f) 2.0
Question 3.
List the features of Python?
Answer:
The features of Python are-
Dynamically typed
Large community support
Object Oriented Programming (OOP)
Free and Open source
Extensible and Embeddable
Introduction to Python Class 9 Long Answer Type Questions
Question 1.
Define control structure in program and its type.
Answer:
A program’s flow of instructions is governed by a set of instructions called a control structure. It is a programming tool that chooses the chronological sequence in which statements in any programming language are executed. Control structures come in three varieties: repetition flow, selection flow, and sequential flow. The details are as follows:
Sequential flow: In sequential flow, the statements are placed one after the other and the flow of execution occurs starting from line1, line2 and so on with a top-down approach.
Selection flow: Selection flow is also known as branching control as the flow of control branches based on a condition. A condition evaluates to either TRUE or FALSE. In the case of TRUE, the flow of control follows the set of instructions written for true.
Repetition flow: Repetition flow is also known as a loop as it repeats a set of instructions a number of times based on a condition.
Question 2.
Write down what is an Algorithm and its advantages disadvantages.
Answer:
An algorithm is a method that identifies and resolves problems in a set amount of time. It is employed at the problem-solving stage of any programming activity and aids in the definition of concise, sequential instructions. An algorithm represents a program’s steps using statements that are similar to those in ordinary English.
Advantages of an Algorithm:
It is a step-by-step representation of a solution to a given problem.
It uses simple English like statements so it is easy to understand and write.
The problem is broken down into smaller pieces hence it is easy to convert it into a program using any programming language.
Disadvantages of an Algorithm:
Since there is no standard rule for writing an algorithm, it varies drastically
It is a time-consuming process
It is difficult to represent branching and looping in an algorithm.
Question 3.
Define what is a flowchart and its advantages disadvantages.
Answer:
A flowchart is a graphical representation of an algorithm. It makes use of symbols which are connected through arrows to show the direction of flow of information.
Advantages of floweharts:
- It is a better way of communication due to its graphical representation.
- It is an effective way to solve and analyze problem.
- It is an easier method of converting a program logic into a code using any programming language.
- The flowchart makes program or system maintenance easier.
- It is used in preparing documentation of an application or a process.
Disadvantages of flowcharts:
- It is a time-consuming process.
- It is difficult to make floweharts for complex and long programs.
- Modification of the program through flowchart is sometimes time-consuming.
Question 4.
What will be the output of the following?
Print (len(str(17//4)))
Print(len(str(17/4)))
Solution:
1
3
Because
len (str(17//4))
= len(str(4))
= len(‘4)
= 1
and
len(str(17 / 4))
= len(str(4.0))
= len(‘4.0’)
= 3
Introduction to Python Class 9 Case-Based Questions
Question 1.
Seema wants to write a python program. The program will store her friends name, roll no, marks, address etc. but she is confused for the kind of data type to use for her variables. Help her in resolving the issue.
(a) name-String, roll-integer, marks-string, address-string
(b) name-String, roll-string, marks-float, address-string
(c) name-String, roll-integer, marks-string, address-float
(d) name-integer, roll-integer, marks-string, address-string
Answer:
(a) name-String, roll-integer, marks-string, address-string
Question 2.
While doing Python Programming Madan got wrong results, on analysis he found that it was due to the poor programming logic. What kind of error it was?
(a) Syntax Error
(b) Logical Error
(c) Runtime error
(d) Semantic error
Answer:
(b) Logical Error
Question 3.
For readability and easy understanding of the program, Suman wants to make some changes in the program. What she should do in her program?
(a) She can add more print() statements
(b) She can add comments into the program
(c) She can add more expressions into the program
(d) She can add input() into the program
Answer:
(b) She can add comments into the program
Question 4.
Radhika is new in Python programming; she wants to store her program for later viewing the codes. Which of the following way of Python working mode is more suitable for her?
(a) Interactive Mode (Python IDLE-Shell Mode)
(b) Script mode to store files on the local computer
(c) Online Jupyter notebook
(d) In Python.org
Answer:
(b) Script mode to store files on the local computer
Question 5.
A Class 9 student named Alex decided to create a simple program to manage a personal library of books using Python. Alex wanted the program to allow adding new books, displaying the list of books, and searching for a book by its title. To achieve this, Alex needed to understand basic Python concepts such as variables, lists, loops, and functions. After learning these concepts, Alex wrote the following program:
Questions:
Question 1.
What are the primary data structures and functions used in Alex’s program to manage the library?
Answer:
Primary Data Structures and Functions:
Data Structure: The program uses a list named library to store the titles of the books.
Functions: The program defines three functions: add_book, display_books, and search_book. Each function performs a specific task related to managing the library.
Question 2.
How does the add_book function work, and what is its purpose in the program?
Answer:
How add_book Works:
- The add_book function takes a book title as an argument and appends it to the library list.
- It then prints a confirmation message indicating that the book has been added.
- Purpose: The function allows users to add new books to the library.
Question 3.
Explain the logic behind the display_books function. How does it handle an empty libraty?
Answer:
Logic of display_books:
- The display_books function checks if the library list is not empty.
- If there are books in the library, it prints each book title in the list.
- If the library is empty, it prints a message indicating that there are no books in the library.
- Handling Empty Library: The function uses an if statement to check if the library list is empty and prints an appropriate message.
Question 4.
Describe how the search_book function checks for the presence of a book in the library.
Answer:
How search_book Checks for a Book:
- The search_book function takes a book title as an argument and checks if the title is present in the library list using the in keyword.
- If the book is found, it prints a message confirming its presence.
- If the book is not found, it prints a message indicating its absence.
Question 5.
Suggest an improvement to the program to handle the case where a user tries to add a book that is already in the library.
Answer:
Suggested Improvement:
To handle the case where a user tries to add a book that is already in the library, the add_book function can be modified to check for the book’s presence before adding it:
This modification ensures that duplicate entries are not added to the library, maintaining the integrity of the data.
Introduction to Python Class 9 Notes
Program- A computer is only a device that produces a result in response to commands or inputs. We must provide the computer with step-by-step instructions if we want the machine to solve an issue. A programme is a set of detailed instructions written in any programming language to carry out a particular activity.
Steps involved in Computer Problem Solving- Before write a program following steps has to follow:
- Understanding the Problem
- Analyzing the Problem
- Developing the Solution
- Coding and Implementation
Control Structure- A set of instructions called a control structure governs how a program’s instructions flow. It is a programming tool that chooses which statements in any programming language are executed in what order.
What is Python-Python is a general-purpose, object oriented, easy to learn and high-level programming language.
Features of Python- High level language, Easy to learn and use, Expressive language, Free and open source, Cross platform language, Interpreted language, Object-oriented language, Support GUI, Large standard library.
Role of Python in Artificial Intelligence- Built-in-Libraries, Platform Independence, Extensible, Availability of Data Analysis Tools, Community Support.
Important uses of Python-Used for web and Internet Application Development, Scientific and Numeric Calculation, Game Development, General-Purpose Software Development.