Python Practical File for Class 10
Python Practical File for Class 10
In Python, compound interest is calculated with the formula `ci = p * ((1 + r / 100)**t - 1)` where `p` is the principal, `r` is the rate of interest, and `t` is the time period in years. Unlike simple interest, which is calculated linearly as `si = (p * r * t) / 100`, compound interest considers the effect of compounding over each time period .
To determine if an integer is positive, negative, or zero in Python, you can use a simple if-elif-else conditional statement. For example, using `if num > 0` to check positivity, `elif num < 0` for negativity, and `else` for zero .
Using a list comprehension in Python, the sum can be computed as `sum([i**2 for i in range(1, 101)])`, which calculates the square of each number from 1 to 100 and then sums the results .
The algorithm first calculates the average of the marks by summing all the marks and dividing by the count. Grades are then assigned based on the average: 'A' for averages greater than or equal to 90, 'B' for averages 80-89, 'C' for averages 70-79, 'D' for 60-69, and 'F' for averages below 60 .
Python dictionaries store data in key-value pairs, allowing fast access and management of related data. For states and capitals, each state name is a key with the capital as the value. Similarly, student data can be managed with student names as keys and their lists of marks as values, facilitating operations like summing marks or retrieving a specific capital or student’s records .
To determine profit or loss, input the cost price (cp) and selling price (sp). If sp > cp, calculate profit as `sp - cp`, if sp < cp, calculate loss as `cp - sp`. No profit or loss is noted when sp equals cp .
Using age as an input, you can employ an if-elif-else structure to determine the life stage. For instance, if age < 13, print 'Child'; elif age < 20, print 'Teenager'; elif age < 60, print 'Adult'; else, print 'Senior Citizen' .
To calculate these quantities, you first define the dimensions: for a triangle, use Heron's formula for the area and sum of sides for the perimeter; for a rectangle, length times width for the area and twice the sum of length and width for the perimeter; for a square, square of the side for the area and four times the side for the perimeter; for a circle, pi times radius squared for the area, and 2 times pi times radius for the circumference .
The EMI for a loan is computed using the formula `EMI = P * monthly_rate * ((1 + monthly_rate) ** T) / ((1 + monthly_rate) ** T - 1)`, where `P` is the loan amount, `monthly_rate` is the monthly interest rate derived from annual interest rate divided by 12, and `T` is the loan duration in months. Both rate and time affect the compound nature of the repayment .
To retrieve the third smallest and third largest unique values, you would first convert the list to a set to ensure uniqueness, then sort the resultant set. The third smallest is the element at index 2, and the third largest is at index -3 of this sorted list .