0% found this document useful (0 votes)
38 views5 pages

Class 10 Advance Python Answers

Unit 3 covers advanced Python concepts including the Anaconda distribution, Jupyter Notebook usage, and virtual environments. It explains various Python operators, loops, and typecasting, as well as the installation and application of libraries like NumPy and Pandas. Additionally, it provides sample programs for calculating income tax and identifying numbers divisible by certain criteria.

Uploaded by

thejerseyvault07
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views5 pages

Class 10 Advance Python Answers

Unit 3 covers advanced Python concepts including the Anaconda distribution, Jupyter Notebook usage, and virtual environments. It explains various Python operators, loops, and typecasting, as well as the installation and application of libraries like NumPy and Pandas. Additionally, it provides sample programs for calculating income tax and identifying numbers divisible by certain criteria.

Uploaded by

thejerseyvault07
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Unit 3: Advance Python

Short answer type questions.

1. Anaconda distribution is a powerful and widely used open source distribution of Python
language for scientific computations, machine learning and data science tasks. It is an
essential tool for data scientists, researchers and developers as it includes essential pre-
installed libraries. It simplifies the process of managing software packages and dependencies.

2. Once you have launched Jupyter Notebook within your virtual environment, you can execute
commands by creating and running Python code cells within a notebook.

• Create a New Notebook or Open an Existing One.

• Once you have a notebook open, you'll see an empty code cell where you can enter
Python code. Click on the cell to select it, and then type or paste your Python code into
the cell.

• After entering your Python code in a cell, you can execute it by either pressing "Shift +
Enter" or clicking the "Run" button in the toolbar. This will run the code in the selected
cell and display the output directly below the cell.

3. Venv module are tools that allow users to create virtual environments. These virtual
environments contain their own Python interpreter and package installation directories. Thus,
each project can have its own set of libraries Python versions to avoid conflicts between
different projects.

4. Membership operators 'in' and 'not in' are used to check if a value exists in a list or sequence or
not.

5. In some cases, a condition in a 'for' or 'while' loop does not ever become false, hence the
statements between the loop keep repeating indefinitely. This is called an infinite loop.

6. The else statement works with single conditions whereas the elif statement is used to test
multiple conditions.

7. A loop inside a loop is called a nested loop.

8. The syntax for nested 'if-else' are:


if condition1:
Code block1
if condition2:
Code block2
else:
Code block3
else:
Code block4

Long answer type questions.

1. The different ways to install Python libraries are:


• Importing the entire library: This allows to access all functionalities of the library: import
numpy

• Importing the library with an alias: This imports the library with an alias name: import
numpy as np

• Importing all functions from a library: This imports all functions and objects from the
library: from numpy import *

2. The uses and applications of any four Python libraries are:

1. NumPy: Stands for Numerical Python. It is a fundamental package for numerical


computations.

2. Pandas: It is a powerful data analysis and manipulation library.

3. MatPlotLib: Comprehensive library for creating static, animated and interactive visualisations
in Python.

4. NLTK: Natural Language Toolkit used for interaction with humans in natural language.

3. The components of Jupyter Notebook are:

• Menu: Located at the top of the page. It includes options to create new notebooks, open
existing notebooks and saving your work.

• Code cells: Used to type and execute programs.

• Markdown cells: Used for adding comments, headings and formatted text.

• Output area: It displays the output of the code. This could be in the form of text, plots,
graphs etc.

4. A division operator (/) performs division and returns a floating-point result, even if the operands
are integers. If both operands are integers, the result will be a floating-point number, including
the fractional part.

• Example:

result = 7 / 2

print(result) # Output: 3.5

• The floor division operator (//) performs division and returns the quotient of the division,
rounded down to the nearest integer. If returns only whole numbers.

• Example:

result = 7 // 2

print(result) # Output: 3

5. The input() function is used to take input from user. It accepts input from the console.

• Example:

name = input("Enter your name")


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

name = input("Enter your name")

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

• The print() function prints a message or value. It converts a value into string before displaying it.

• Example:

print("Hello, ", name) #name is a variable in which a string has been accepted

6. The 'for' loop is used when you are sure about the number of times a loop body will be
executed. It is also known as a definite loop. Whereas, the 'while' loop in Python executes a set
of statements based on a condition. If the test expression evaluates to true, then the body of
the loop gets executed. Otherwise, the loop stops iterating and the control comes out of the
body of the loop.

• For Loop Flowchart

• While Loop Flowchart

7. Nested if statements in Python refer to if statements that are placed inside other if statements.
The inner if statement gets executed only if the outer is true. An example to check if a number is
non-zero and odd or even:

num = int(input("Enter a number: "))

# Check if the number is positive

if num >= 0:

# Check if the number is even

if num % 2 == 0:

print("The number is even.")

else:
print("The number is odd.")

8. The process of converting one data type to another is called typecasting.

• Types of typecasting are:

• Implicit typecasting: The typecasting where one data type is automatically converted to
another is called implicit typecasting. This makes programming simpler.

• Example:

num1 = 10

num2 = 20.5

sum = num1 + num2

• Here sum is automatically converted to a float, which is the higher data type.

• Explicit typecasting: In this type, the data type conversion is done manually by using int(),
float() and str() functions.

• Example:

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

Here the input by the user is explicitly converted into an integer value and assigned to the variable age.

9. The program to display numbers divisible by 7 and multiples of 5 between 1200 and 2200 is:
start = 1200
end = 2200
# Iterate through the range and display numbers meeting the criteria
print("Numbers divisible by 7 and multiples of 5 between 1200 and 2200:")
for num in range(start, end + 1):
if num % 7 == 0 and num % 5 == 0:
print(num)
10. The program to enter the monthly income of an employee between 40 and 60 years and
calculate the annual income tax is:

monthly_income = float(input("Enter the monthly income of the employee: "))

# Calculate annual income

annual_income = monthly_income * 12

# Calculate annual income tax based on income range

if annual_income <= 300000:

tax_amount = 0

elif annual_income <= 500000:

tax_percentage = 5
tax_amount = (annual_income * tax_percentage) / 100

elif annual_income <= 1000000:

tax_percentage = 20

tax_amount = (annual_income * tax_percentage) / 100

else:

tax_percentage = 30

tax_amount = (annual_income * tax_percentage) / 100

# Display the annual income tax

print("Annual Income Tax: ", tax_amount)

You might also like