Python in AI Class 11 NCERT Solutions

Share with others

Python in AI Class 11 NCERT Solutions – The CBSE has updated the syllabus for St. XI (Code 843). The NCERT Solutions are made based on the updated CBSE textbook. All the important information is taken from the Artificial Intelligence Class XI Textbook Based on the CBSE Board Pattern.

Python in AI Class 11 NCERT Solutions

A. Multiple choice questions

1. Identify the datatype L = “45”
a. String
b. int
c. float
d. tuple

Show Answer ⟶
a. String

2. Which of the following function converts a string to an integer in python?
a. int(x)
b. long(x)
c. float(x)
d. str(x)

Show Answer ⟶
a. int(x)

3. Which special symbol is used to add comments in python?
a. $
b. //
c. /*…. */
d. #

Show Answer ⟶
d. #

4. Which of the following variable is valid?
a. Str name b.1str
b. 1str
c._str
d. #Str

Show Answer ⟶
c. _str

5. Elements in the list are enclosed in _ brackets
a. ( )
b. { }
c. [ ]
d. /* */

Show Answer ⟶
c. [ ]

6. Index value of last element in list is ________
a. 0
b. -10
c. -1
d. 10

Show Answer ⟶
c. -1

7. What will be the output of the following code.
a = [10,20,30,40,50]
print([0])
a.20
b.50
c. 10
d.40

Show Answer ⟶
c. 10

8. Name the function that displays the data type of the variable.
a. data( )
b. type( )
c. datatype( )
d. int()

Show Answer ⟶
b. csv

9. Which library helps in manipulating csv files?
a. files
b. csv
c. math
d. print

Show Answer ⟶
b. csv

10. Which keyword can be used to stop a loop?
a. stop
b. break
c. brake
d. close

Show Answer ⟶
b. break

11. What is the primary data structure used in NumPy to represent arrays of any dimension?
a. Series
b. DataFrame
c. ndarray
d. Panel

Show Answer ⟶
c. ndarray

12. Which of the following is not a valid method to access elements of a Pandas DataFrame?
a. Using column names as attributes.
b. Using row and column labels with the .loc[] accessor.
c. Using integer-based indexing with the .iloc[] accessor.
d. Using the .get() method.

Show Answer ⟶
d. Using the .get() method

13. What is the purpose of the head() method in Pandas?
a To display the first few rows of a DataFrame.
b. To display the last few rows of a DataFrame.
c. To count the number of rows in a DataFrame.
d. To perform aggregation operations on a DataFrame.

Show Answer ⟶
a. To display the first few rows of a DataFrame.

14. Which method is used to drop rows with missing values from a DataFrame in Pandas?
a. drop_rows()
b. remove_missing()
c. dropna()
d. drop_missing_values

Show Answer ⟶
c. dropna()

15. Which is not a module of Sklearn?
a. load_iris
b. train_test_split
c. metrics
d. Scikit

Show Answer ⟶
d. Scikit

B. Answer the following questions

1. input() function accepts the value as string only. How can you convert string to int?

Answer:

bill = float(input("Enter restaurant bill amount: "))
tip_15 = bill * 0.15
tip_20 = bill * 0.20

2. What are variables? What are the rules of declaring variables in Python?

Answer: A Python variable is just like a container that can store data values. Python does not have a command for declaring a variable.

Rules for declaring variables in Python,

  • A variable name must start with a letter or underscore.
  • A variable name cannot start with a number.
  • A variable can contain only alphanumeric characters and underscores (a-z, 0-9, and _).
  • Variable names are case sensitive.
  • A variable name cannot be used from Python keywords.

3. What do you mean by type casting?

Answer: Type casting is also known as type conversion. It is a process for converting the value of a single data type to another data type. This conversion can be done automatically or manually. There are two types of casting:

  • Implicit type casting
  • Explicit type casting

4. “Python supports dynamic typing”, True or False. Justify your answer.

Answer: Dynamic typing means that the nature of the variables is decided at runtime. Python supports Dynamic Typing. A variable pointing to a value of certain data type can be made to point to a value/object of another data type. This is called Dynamic Typing.

5. Name any four features of python language.

Answer: The four features of python language are –

  • High Level language & Easy to use and learn
  • Interpreted Language
  • Free and Open Source
  • Platform Independent (Cross-Platform) – runs virtually in every platform if a
  • compatible python interpreter is installed.

6. Give examples for keywords.

Answer: Reserved words used for special purpose. List of keywords are given below.
False, None, True, for, in, or, while, and, class, elif, from, is, pass, with etc.

7. Expand CSV.

Answer: CSV files are delimited files that store tabular data (data stored in rows and columns). It looks similar to spread sheets, but internally it is stored in a different format. In csv file, values are separated by comma.

7. How do you read data from a CSV file into a Pandas DataFrame?

Answer: You use the read_csv() function to read the data from the CSV file. To read the file, you have to provide the file path as a string and make sure the file name and extension are also given in the path.

import pandas as pd
df = pd.read_csv('your_file.csv')
print(df.head())

C. Long Answer Questions

1. Describe the data types supported by Python, providing relevant examples.

Answer: Data types are the classification or categorization of data items. The data types supported by Python are –

  • Integer: Stores whole number
  • Boolean: Boolean is used to represent the truth values of the expressions. It has two values True & False
  • Floating point: Stores numbers with fractional part
  • Complex: Stores a number having real and imaginary part
  • String: Immutable sequences (After creation values cannot be changed in-place), Stores text enclosed in single or double quotes
  • List: Mutable sequences (After creation values can be changed in-place), Stores list of comma separated values of any data type between square [ ]
  • Tuple: Immutable sequence (After creation values cannot be changed in-place), Stores list of comma separated values of any data type between parentheses ( )
  • Set: Set is an unordered collection of values, of any type, with no duplicate entry.
  • Dictionary: Unordered set of comma-separated key:value pairs within braces {}

2. Define an operator and provide examples of different operators along with their functions.

Answer: Operators are symbols or keywords that perform operations on operands to produce a result, Python supports a wide range of operators:

  • Arithmetic operators (+, -, *, /, %)
  • Relational operators (==, !=, <, >, <=, >=)
  • Assignment operators (=, +=, -=)
  • Logical operators (and, or, not)
  • Bitwise operators (&, |, ^, <<, >>)
  • Identity operators (is, is not)
  • Membership operators (in, not in)

D. Practice Programs

1. Write a Tipper program where the user inputs the total restaurant bill. The program should then display two amounts: 15 percent tip and 20 percent tip.

Answer:

bill = float(input("Enter restaurant bill amount: "))
tip_15 = bill * 0.15
tip_20 = bill * 0.20

2. Write a program to check whether the user is eligible for driving license or not.

Answer:

age = int(input("Enter your age: "))

if age >= 18:
print("You are eligible for a driving license.")
else:
print("You are not eligible for a driving license.")

3. Your father always gives his car for service after 15000 km. Check whether his car needs service or not. Read the kilometer reading from the user and give the output.

Answer:

km = int(input("Enter the current kilometer reading: "))

if km >= 15000:
print("Your car needs service.")
else:
print("Your car does not need service")

4. Write a program to display the first ten even natural numbers (use for loop).

Answer:

print("The first ten even natural numbers are:")
for i in range(2, 21, 2):
    print(i)

5. Write a program to accept the Basic salary from the user and calculate the Net Salary.
Net Salary= Basic Salary + HRA + DA -PF
HRA=30% of Basic
DA=20% of Basic
PF=12% of Basic

Answer:

basic_salary = float(input("Enter the Basic Salary: "))
HRA = 0.30 * basic_salary
DA = 0.20 * basic_salary
PF = 0.12 * basic_salary
net_salary = basic_salary + HRA + DA - PF

print(f"Net Salary: {net_salary}")

6. Write a program to create series from an array in Python.

Answer:

import pandas as pd
data = {
    'Name': ['Amit', 'Ashu', 'Abhinav', 'Ravi', 'Rashmi', 'Ramesh', 'Mohit', 'Manavi', 'Dhruv'],
    'Class': [10, 9, 9, 10, 11, 10, 9, 10, 9],
    'Gender': ['M', 'F', 'M', 'M', 'F', 'M', 'M', 'F', 'M'],
    'Marks': [75, 95, 86, 57, 78, 72, 53, 47, 76]
}
df = pd.DataFrame(data)
print("DataFrame:")
print(df)

7. Consider the following admission.csv and answer the following questions:

Consider the following admission.csv and answer the following questions

a. Create a dataframe from the admission.csv
b. Display first 3 rows of the dataframe.
c. Display the details of Ravi.
d. Display the total number of rows and columns in the data frame.
e. Display the column “Gender”.

Answer:

a. Create a dataframe from the admission.csv

import pandas as pd
data = {
    'Name': ['Amit', 'Ashu', 'Abhinav', 'Ravi', 'Rashmi', 'Ramesh', 'Mohit', 'Manavi', 'Dhruv'],
    'Class': [10, 9, 9, 10, 11, 10, 9, 10, 9],
    'Gender': ['M', 'F', 'M', 'M', 'F', 'M', 'M', 'F', 'M'],
    'Marks': [75, 95, 86, 57, 78, 72, 53, 47, 76]
}
df = pd.DataFrame(data)
print("DataFrame:")
print(df)

b. Display first 3 rows of the dataframe.

Answer:

print("\nFirst 3 rows:")
print(df.head(3))

c. Display the details of Ravi.

Answer:

ravi_details = df[df['Name'] == 'Ravi']
print("\nDetails of Ravi:")
print(ravi_details)

d. Display the total number of rows and columns in the data frame.

Answer:

rows, columns = df.shape
print(f"\nTotal number of rows: {rows}")
print(f"Total number of columns: {columns}")

e. Display the column “Gender”.

Answer:

print("\nGender column:")
print(df['Gender'])


Disclaimer: We have taken an effort to provide you with the accurate handout of “Python in AI Class 11 NCERT Solutions“. If you feel that there is any error or mistake, please contact me at anuraganand2017@gmail.com. The above CBSE study material present on our websites is for education purpose, not our copyrights. All the above content and Screenshot are taken from Artificial Intelligence Class 11 CBSE Textbook, Sample Paper, Old Sample Paper, Board Paper and Support Material which is present in CBSEACADEMIC website, This Textbook and Support Material are legally copyright by Central Board of Secondary Education. We are only providing a medium and helping the students to improve the performances in the examination. 

Images and content shown above are the property of individual organizations and are used here for reference purposes only.

For more information, refer to the official CBSE textbooks available at cbseacademic.nic.in

cbseskilleducation


Share with others

Leave a Comment