[Go to site: main page, start]

0% found this document useful (0 votes)
79 views4 pages

Python Practical File for Class 10

The document contains a practical Python file with various code snippets demonstrating fundamental programming concepts. It includes examples for checking number signs, calculating averages and grades, determining age categories, computing sale prices, and performing financial calculations like interest and EMI. Additionally, it covers list operations, string manipulations, and dictionary usage for states and student marks.

Uploaded by

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

Python Practical File for Class 10

The document contains a practical Python file with various code snippets demonstrating fundamental programming concepts. It includes examples for checking number signs, calculating averages and grades, determining age categories, computing sale prices, and performing financial calculations like interest and EMI. Additionally, it covers list operations, string manipulations, and dictionary usage for states and student marks.

Uploaded by

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

Python Practical File with Code

1. Check whether the given number is Positive, Negative or Zero


num = int(input("Enter a number: "))
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")

2. Print even numbers from a list using for loop


l1 = [1, 2, 3, 4, 5, 6]
for num in l1:
if num % 2 == 0:
print(num)

3. Find average and grade for marks given in a list


marks = [88, 92, 76, 81, 95]
average = sum(marks) / len(marks)
if average >= 90:
grade = 'A'
elif average >= 80:
grade = 'B'
elif average >= 70:
grade = 'C'
elif average >= 60:
grade = 'D'
else:
grade = 'F'
print("Average:", average)
print("Grade:", grade)

4. Age category based on user input


age = int(input("Enter your age: "))
if age < 13:
print("Child")
elif age < 20:
print("Teenager")
elif age < 60:
print("Adult")
else:
print("Senior Citizen")
5. Find sale price with discount
cost = float(input("Enter cost price: "))
discount = float(input("Enter discount percentage: "))
sale_price = cost - (discount / 100) * cost
print("Sale Price:", sale_price)

6. Perimeter and area of triangle, rectangle, square, and circle


import math
# Triangle
a, b, c = 3, 4, 5
s = (a + b + c) / 2
area_triangle = [Link](s * (s - a) * (s - b) * (s - c))
print("Triangle Area:", area_triangle, "Perimeter:", a + b + c)

# Rectangle
l, w = 5, 3
print("Rectangle Area:", l * w, "Perimeter:", 2 * (l + w))

# Square
side = 4
print("Square Area:", side**2, "Perimeter:", 4 * side)

# Circle
r = 3
print("Circle Area:", [Link] * r**2, "Circumference:", 2 *
[Link] * r)

7. Simple and Compound Interest


p = float(input("Enter principal: "))
r = float(input("Enter rate of interest: "))
t = float(input("Enter time in years: "))
si = (p * r * t) / 100
ci = p * ((1 + r / 100)**t - 1)
print("Simple Interest:", si)
print("Compound Interest:", ci)

8. Profit and Loss


cp = float(input("Enter cost price: "))
sp = float(input("Enter selling price: "))
if sp > cp:
print("Profit:", sp - cp)
elif sp < cp:
print("Loss:", cp - sp)
else:
print("No Profit No Loss")
9. Calculate EMI
P = float(input("Enter loan amount: "))
R = float(input("Enter annual interest rate: "))
T = int(input("Enter loan duration in months: "))
monthly_rate = R / (12 * 100)
emi = P * monthly_rate * ((1 + monthly_rate) ** T) / ((1 +
monthly_rate) ** T - 1)
print("EMI:", emi)

10. Calculate GST and Income Tax


amount = float(input("Enter amount: "))
gst = amount * 0.18
income_tax = amount * 0.10
print("GST:", gst)
print("Income Tax:", income_tax)

11. Find largest and smallest in list


l = [4, 1, 9, 2, 7]
print("Largest:", max(l))
print("Smallest:", min(l))

12. Third largest and third smallest in list


l = [10, 20, 5, 8, 30, 20]
unique_sorted = sorted(set(l))
print("Third Largest:", unique_sorted[-3])
print("Third Smallest:", unique_sorted[2])

13. Sum of squares of first 100 natural numbers


total = sum([i**2 for i in range(1, 101)])
print("Sum of squares:", total)

14. First 'n' multiples of a number


n = int(input("Enter a number: "))
count = int(input("Enter how many multiples: "))
for i in range(1, count+1):
print(n * i)

15. Count vowels in a string


s = input("Enter a string: ")
vowels = "aeiouAEIOU"
count = sum(1 for char in s if char in vowels)
print("Vowel count:", count)
16. Print words starting with an alphabet
s = input("Enter a string: ")
alphabet = input("Enter a starting alphabet: ")
words = [Link]()
for word in words:
if [Link]().startswith([Link]()):
print(word)

17. Count occurrences of an alphabet in each word


s = input("Enter a string: ")
alphabet = input("Enter an alphabet to count: ")
words = [Link]()
for word in words:
print(f"{word}: {[Link]().count([Link]())}")

18. Dictionary of States and Capitals


states = {
"Rajasthan": "Jaipur",
"Maharashtra": "Mumbai",
"UP": "Lucknow"
}
print(states)

19. Dictionary of Students and their Marks


students = {
"Amit": [85, 92, 78, 88, 90],
"Priya": [90, 91, 89, 95, 94]
}
print(students)

20. Highest and Lowest Total Marks in Dictionary


students = {
"Amit": [85, 92, 78, 88, 90],
"Priya": [90, 91, 89, 95, 94]
}
totals = {name: sum(marks) for name, marks in [Link]()}
highest = max(totals, key=[Link])
lowest = min(totals, key=[Link])
print("Highest:", highest, totals[highest])
print("Lowest:", lowest, totals[lowest])

Common questions

Powered by AI

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 .

You might also like