Untitled Document
Untitled Document
1.
2. What are variables? What are the rules of declaring variables in Python?
Answer: Variables are names used to store data in memory.
Rules:
float_value = float(10)
3.
x = 10 # Initially an integer
x = "Hello" # Now a string
4.
5. Name any four features of Python language.
Answer:
How do you read data from a CSV file into a Pandas DataFrame?
Answer: Use pandas.read_csv() method.
Example:
import pandas as pd
df = pd.read_csv("file.csv")
8.
1. Describe the data types supported by Python, providing relevant examples.
Answer:
○ Arithmetic: +, -, *, /. Example: x + y
○ Relational: <, >, ==. Example: x > y
○ Logical: and, or, not. Example: x > 5 and y < 10
○ Assignment: =, +=. Example: x += 1
D. Practice Programs
Tipper Program
1.
2.
3.
4.
5.
import pandas as pd
import numpy as np
array = np.array([1, 2, 3, 4, 5])
series = pd.Series(array)
print(series)
6.
import pandas as pd
# a. Create a dataframe
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)
7.
The Python unit includes several exercises involving programming tasks. Below, I'll provide
answers and explanations for the questions in the unit:
Sample Program-1
print("National Animal-Tiger")
Sample Program-2
Task: Write a program to calculate the area of a rectangle with length 50 and breadth 20.
Code:
length = 50
breadth = 20
area = length * breadth
print("Area of the rectangle:", area)
Sample Program-3
Task: Read the name and marks of a student and display the total mark.
Code:
Sample Program-4
Task: Determine the choice of food according to menu options (Veg, Non-Veg).
Code:
Sample Program-5
if a == b == c:
print("Equilateral Triangle")
elif a == b or b == c or a == c:
print("Isosceles Triangle")
else:
print("Scalene Triangle")
Sample Program-6
Task: Display even numbers and their squares between 100 and 110.
Code:
Sample Program-7
Sample Program-8
Task: Split a string into words and display each word.
Code:
Sample Program-9
Sample Program-10
import csv
Conceptual Questions
This covers the solutions and explanations for the Python unit exercises in the handbook. If you
have any specific programs or doubts, let me know!