0% found this document useful (0 votes)
4 views11 pages

Python Assignments for Grade 10 Students

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)
4 views11 pages

Python Assignments for Grade 10 Students

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

BARNES SCHOOL & JUNIOR COLLEGE, DEVLALI

2025-2026

GRADE : 10

PYTHON ASSIGNMENTS

Assignment No. 1

Write a Python program to create a list of student names and

sort them in alphabetical order:

✅ Python Program:

# Create an empty list


students = []

# Get number of students


n = int(input("Enter number of students: "))

# Input names
for i in range(n):
name = input(f"Enter name of student {i+1}: ")
[Link](name)

# Sort the list alphabetically


[Link]()

# Display sorted list


print("\nSorted list of students:")
for name in students:
print(name)

Sample Input/Output:

Input:

Enter number of students: 4


Enter name of student 1: Zoya
Enter name of student 2: Amit
Enter name of student 3: Riya
Enter name of student 4: John

Output:

Sorted list of students:


Amit
John
Riya
Zoya
Assignment No .2

Find a word string of interest in a given sentence. For the same string, match for exact case if a
particular word string is present in a given sentence. Display the output "String name found "String
name not found ". in Python program.

✅ Python Program: Find Word in Sentence (Case-Sensitive)

# Input sentence and word to search


sentence = input("Enter a sentence: ")
search_word = input("Enter the word to search: ")

# Case-sensitive match
if search_word in sentence:
print(f'"{search_word}" found')
else:
print(f'"{search_word}" not found')

Sample Input (Match Found)

Input:

Enter a sentence: Python is Fun


Enter the word to search: Fun

Output:

"Fun" found

Sample Input 2 (Match Not Found due to case)

Input:

Enter a sentence: Python is Fun


Enter the word to search: fun

Output:

"fun" not found

Assignment No.3
#Make a dictionary dataset of all cities in India and store their average temperature and
#pollution details in Python.

# Creating a dictionary with city names as keys

city_data = {

"Delhi": {

"average_temperature": 25, # in Celsius


"pollution_level": 300 # AQI (Air Quality Index)

},

"Mumbai": {

"average_temperature": 28, # in Celsius

"pollution_level": 150 # AQI

},

"Kolkata": {

"average_temperature": 30, # in Celsius

"pollution_level": 180 # AQI

},

"Bangalore": {

"average_temperature": 22, # in Celsius

"pollution_level": 85 # AQI

},

# Example of accessing data

for city, data in city_data.items():

print(f"City: {city}")

print(f" Average Temperature: {data['average_temperature']}°C")

print(f" Pollution Level (AQI): {data['pollution_level']}")

print()

Sample Output :

City: Delhi

Average Temperature: 25°C

Pollution Level (AQI): 300

City: Mumbai

Average Temperature: 28°C

Pollution Level (AQI): 150


City: Kolkata

Average Temperature: 30°C

Pollution Level (AQI): 180

City: Bangalore

Average Temperature: 22°C

Pollution Level (AQI): 85

Assignment NO : 4

Write a Python program to calculate the electricity bill. Accept the last meter reading and
current meter reading and the rate per unit from the user. Calculate the number of units and
total bill consumption for the user .

# Accept inputs from the user

last_reading = float(input("Enter last meter reading (in units): "))

current_reading = float(input("Enter current meter reading (in units): "))

rate_per_unit = float(input("Enter rate per unit (in ₹): "))

# Calculate units consumed

units_consumed = current_reading - last_reading

# Ensure the reading is valid

if units_consumed < 0:

print("Error: Current reading should be greater than or equal to last reading.")

else:

# Calculate total bill

total_bill = units_consumed * rate_per_unit

# Display the results

print(f"\nUnits consumed: {units_consumed} units")

print(f"Rate per unit: ₹{rate_per_unit}")

print(f"Total bill: ₹{total_bill:.2f}")


Solution:

Sample Input 1 :

Enter last meter reading (in units): 1500

Enter current meter reading (in units): 1650

Enter rate per unit (in ₹): 6.5

Sample Input 2:

Units consumed: 150.0 units

Rate per unit: ₹6.5

Total bill: ₹975.00

Assignment No : 5

A company decided to give bonus of 5% to an employee if his/her year of service is more


than 5 years. Write a Python program to ask the user for their salary and year of service and
print the net bonus amount.

Solution :

# Get user input for salary and years of service

salary = float(input("Enter your salary: "))

years_of_service = int(input("Enter your years of service: "))

# Check eligibility and calculate bonus

if years_of_service > 5:

bonus = 0.05 * salary

print(f"You are eligible for a bonus of ₹{bonus:.2f}")

else:

print("You are not eligible for a bonus.")

Sample Input/Output:

Input:
Enter your salary: 50000
Enter your years of service: 6

Output:

You are eligible for a bonus of ₹2500.00

Input:

Enter your salary: 45000


Enter your years of service: 4

Output:

You are not eligible for a bonus.

Assignment No : 6

#Write a Python program which checks whether a given string

is a Palindrome string or not.

Hint : A Palindrome string is a string whose reverse is same as

The original string.

Example :

Palindrome words are :

nitin

arora

madam

Solution :

def is_palindrome(number):

original = str(number)

reversed_num = original[::-1]

return original == reversed_num

# Calling the above method

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

if is_palindrome(num):

print(f"{num} is a palindrome.")
else:

print(f"{num} is not a palindrome.")

Assignment No. 7

Write a Python program which displays the factorial of a given number.

Sample Input : 5

Sample Output : Factorial = 120

Solution :

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

fact = 1

for i in range(1, n+1):

fact *= i

print("Factorial =", fact)

Assignment No. 8

Write a Python program to check whether a given number is a Palindrome number or not.

Hint : A Palindrome Number is a number whose reverse is equal to the original number.

Example : 5225, 929

Solution :

n = int(input("Enter number: "))

original = n

rev = 0

while n > 0:

rev = rev * 10 + n % 10

n /= 10

if original == rev:

print("Palindrome number")

else:

print("Not a palindrome number")

Assignment No. 9

Write a Python program to count the number of vowels present in the given string.
Sample Input : Barnes School

Sample Output : Vowel count :4

Solution :

s = input("Enter a string: ").lower()

count = 0

for ch in s:

if ch in "aeiou":

count += 1

print("Vowel count:", count)

Assignment No. 10

Write a Python program to print the sum of digits of a given number.

Sample Input : Enter number:527

Sample Output : Sum of digits :14

Solution :

n = int(input("Enter number: "))

sum = 0

while n > 0:

sum += n % 10

n /= 10

print("Sum of digits:", sum)

Assignment No.11

Write a Python program which defines a method named is_prime() which checks

Whether an argument passed is prime number or not.

Solution :

def is_prime(n):

if n <= 1:

return False

for i in range(2, int(n**0.5)+1):

if n % i == 0:

return False

return True
n = int(input("Enter number: "))

print("Prime" if is_prime(n) else "Not prime")

Assignment No. 12

Write a Python program to print prime numbers from 1 to 50

Hint : A Prime number is a number which is divisible by 1 and itself.

Solution:

for num in range(2, 51):

is_prime = True

for i in range(2, int(num ** 0.5)+1):

if num % i == 0:

is_prime = False

break

if is_prime:

print(num, end=" ")

Assignment No.13

Write a Python program to find the frequency of a character in the given string

Sample Input :

Enter string: malalyalam

Enter character to count: a

Sample Output :

Frequency: 4

Solution :

s = input("Enter string: ")

char = input("Enter character to count: ")

print("Frequency:", [Link](char))

Assignment No. 14

Write a Python program which search or find a data using Linear Search technique

Sample Input :

Enter number to search: 20


Sample Output :

Found at index 1

Solution :

lst = [10, 20, 30, 40, 50]

key = int(input("Enter number to search: "))

if key in lst:

print("Found at index", [Link](key))

else:

print("Not found")

Sample Input :

Enter number to search: 20

Sample Output :

Found at index 1

Assignment No.15

Write a Python program to check whether a given number is an Armstrong number or not.

Hint : An Armstrong number is a number whose sum of the cube of digits is equal to

the original number.

Sample Input : 153

Sample Output : 153 is an Armstrong number

Solution :

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

sum = 0

temp = n

while temp > 0:

digit = temp % 10

sum += digit ** 3

temp //= 10

if sum == n:

print("Armstrong number")
else:

print("Not an Armstrong number")

You might also like