Python Practical Solutions - Class XI
1. Enter First and Last Name, Display Full Name
first_name = input("Enter your first name: ")
last_name = input("Enter your last name: ")
full_name = first_name + " " + last_name
print("Full Name:", full_name)
Output:
Input: John, Doe
Output: Full Name: John Doe
2. Add Two Numbers
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
sum = num1 + num2
print("Sum:", sum)
Output:
Input: 5, 10
Output: Sum: 15.0
3. Calculate Perimeter of a Rectangle
length = float(input("Enter length: "))
width = float(input("Enter width: "))
perimeter = 2 * (length + width)
print("Perimeter:", perimeter)
Output:
Input: 5, 10
Output: Perimeter: 30.0
4. Calculate Area of a Triangle
base = float(input("Enter base: "))
height = float(input("Enter height: "))
area = 0.5 * base * height
print("Area of Triangle:", area)
Output:
Input: 5, 10
Output: Area of Triangle: 25.0
5. Calculate Simple Interest
principal = float(input("Enter principal amount: "))
Python Practical Solutions - Class XI
rate = float(input("Enter rate of interest: "))
time = float(input("Enter time in years: "))
si = (principal * rate * time) / 100
print("Simple Interest:", si)
Output:
Input: 1000, 5, 2
Output: Simple Interest: 100.0
6. Check if a Number is Positive, Negative, or Zero
num = float(input("Enter a number: "))
if num > 0:
print("Positive number")
elif num < 0:
print("Negative number")
else:
print("Zero")
Output:
Input: -3
Output: Negative number
7. Check if a Number is Even or Odd
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even number")
else:
print("Odd number")
Output:
Input: 7
Output: Odd number
8. Calculate Total Marks, Percentage, and Grade
marks = []
for i in range(5):
marks.append(float(input(f"Enter marks for subject {i+1}: ")))
total = sum(marks)
percentage = total / 5
grade = "A" if percentage >= 90 else "B" if percentage >= 75 else "C" if percentage >=
50 else "D"
print("Total Marks:", total, "Percentage:", percentage, "Grade:", grade)
Output:
Python Practical Solutions - Class XI
Input: 80, 85, 78, 90, 88
Output: Total Marks: 421, Percentage: 84.2, Grade: B
9. Check if a Year is a Leap Year
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print("Leap Year")
else:
print("Not a Leap Year")
Output:
Input: 2024
Output: Leap Year
10. Print Numbers from 1 to 10 using a For Loop
for i in range(1, 11):
print(i, end=" ")
Output:
Output: 1 2 3 4 5 6 7 8 9 10
11. Print Multiplication Table of a Given Number
num = int(input("Enter a number: "))
for i in range(1, 11):
print(num, "x", i, "=", num * i)
Output:
Input: 5
Output:
5 x 1 = 5
5 x 2 = 10
...
5 x 10 = 50
12. Print Sum of First Ten Odd Numbers
sum_odds = sum([i for i in range(1, 20, 2)])
print("Sum of first ten odd numbers:", sum_odds)
Output:
Output: Sum of first ten odd numbers: 100
13. Find the Average of 5 Numbers in a List
numbers = [float(input(f"Enter number {i+1}: ")) for i in range(5)]
Python Practical Solutions - Class XI
average = sum(numbers) / len(numbers)
print("Average:", average)
Output:
Input: 10, 20, 30, 40, 50
Output: Average: 30.0
14. Display Even Numbers from a List
numbers = [float(input(f"Enter number {i+1}: ")) for i in range(5)]
evens = [num for num in numbers if num % 2 == 0]
print("Even Numbers:", evens)
Output:
Input: 1, 2, 3, 4, 5
Output: Even Numbers: [2, 4]
15. Create a Dictionary of Students and Marks
students = {}
for i in range(5):
name = input("Enter student name: ")
marks = float(input("Enter marks: "))
students[name] = marks
print("Student Marks Dictionary:", students)
Output:
Input:
Student1 -> 90
Student2 -> 85
Student3 -> 78
Student4 -> 92
Student5 -> 88
Output: {'Student1': 90, 'Student2': 85, 'Student3': 78, 'Student4': 92, 'Student5': 88}