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

Grade11 Python Programs

The document provides Python programs for various basic tasks including arithmetic operations, area and perimeter calculations, swapping numbers, simple interest calculation, temperature conversion, digit summation, number classification, finding the largest of three numbers, counting vowels in a string, and reversing a list. Each program includes sample code and output examples. These programs serve as practical exercises for understanding fundamental programming concepts in Python.

Uploaded by

prajwal919212
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)
2 views4 pages

Grade11 Python Programs

The document provides Python programs for various basic tasks including arithmetic operations, area and perimeter calculations, swapping numbers, simple interest calculation, temperature conversion, digit summation, number classification, finding the largest of three numbers, counting vowels in a string, and reversing a list. Each program includes sample code and output examples. These programs serve as practical exercises for understanding fundamental programming concepts in Python.

Uploaded by

prajwal919212
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
You are on page 1/ 4

Computer Science - Python Programs for Lab records

1. Arithmetic Operations on Two Numbers


Code:

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


b = int(input("Enter second number: "))
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
print("Floor Division:", a // b)
print("Modulus:", a % b)
print("Exponentiation:", a ** b)

Sample Output:

Enter first number: 10


Enter second number: 3
Addition: 13
Subtraction: 7
Multiplication: 30
Division: 3.3333333333333335
Floor Division: 3
Modulus: 1
Exponentiation: 1000

2. Area and Perimeter of a Rectangle


Code:

length = float(input("Enter length: "))


breadth = float(input("Enter breadth: "))
area = length * breadth
perimeter = 2 * (length + breadth)
print("Area:", area)
print("Perimeter:", perimeter)

Sample Output:

Enter length: 5
Enter breadth: 3
Area: 15.0
Perimeter: 16.0
3. Swapping Two Numbers Without Temporary Variable
Code:

x = int(input("Enter first number: "))


y = int(input("Enter second number: "))
x, y = y, x
print("After swapping:")
print("x =", x)
print("y =", y)

Sample Output:

Enter first number: 4


Enter second number: 7
After swapping:
x=7
y=4

4. Simple Interest Calculation


Code:

p = float(input("Enter principal: "))


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

Sample Output:

Enter principal: 1000


Enter rate of interest: 5
Enter time (in years): 2
Simple Interest: 100.0

5. Celsius to Fahrenheit Conversion


Code:

c = float(input("Enter temperature in Celsius: "))


f = (c * 9/5) + 32
print("Temperature in Fahrenheit:", f)

Sample Output:

Enter temperature in Celsius: 25


Temperature in Fahrenheit: 77.0
6. Sum of Digits of a Number
Code:

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


sum_digits = 0
temp = num
while temp > 0:
digit = temp % 10
sum_digits += digit
temp //= 10
print("Sum of digits:", sum_digits)

Sample Output:

Enter a number: 1234


Sum of digits: 10

7. Check if Number is Positive, Negative, or Zero


Code:

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


if n > 0:
print("Positive")
elif n < 0:
print("Negative")
else:
print("Zero")

Sample Output:

Enter a number: -5
Negative

8. Largest of Three Numbers


Code:

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


b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
if a >= b and a >= c:
print("Largest number:", a)
elif b >= a and b >= c:
print("Largest number:", b)
else:
print("Largest number:", c)
Sample Output:

Enter first number: 10


Enter second number: 20
Enter third number: 15
Largest number: 20

9. Count Vowels in a String


Code:

text = input("Enter a string: ")


count = 0
for char in text.lower():
if char in 'aeiou':
count += 1
print("Number of vowels:", count)

Sample Output:

Enter a string: Hello World


Number of vowels: 3

10. Reverse a List


Code:

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


lst = []
for i in range(n):
val = int(input("Enter element: "))
lst.append(val)
lst.reverse()
print("Reversed list:", lst)

Sample Output:

Enter number of elements: 4


Enter element: 10
Enter element: 20
Enter element: 30
Enter element: 40
Reversed list: [40, 30, 20, 10]

You might also like