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

Python Practical File

The document contains Python code examples for various practical exercises, including calculating area and perimeter of shapes, checking even or odd numbers, verifying voting age, and implementing a simple calculator. Each example includes source code, input prompts, and sample outputs. The exercises are designed to help users practice basic programming concepts and operations in Python.

Uploaded by

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

Python Practical File

The document contains Python code examples for various practical exercises, including calculating area and perimeter of shapes, checking even or odd numbers, verifying voting age, and implementing a simple calculator. Each example includes source code, input prompts, and sample outputs. The exercises are designed to help users practice basic programming concepts and operations in Python.

Uploaded by

vesporiansna
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 Holiday Homework

1. Area and Perimeter of a Rectangle


Source Code:

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


width = float(input('Enter width: '))
area = length * width
perimeter = 2 * (length + width)
print(f'Area: {area}, Perimeter: {perimeter}')

Output:

Enter length: 5
Enter width: 4
Area: 20.0, Perimeter: 18.0

2. Area and Circumference of a Circle


Source Code:

import math
radius = float(input('Enter radius: '))
area = [Link] * (radius ** 2)
circumference = 2 * [Link] * radius
print(f'Area: {area:.2f}, Circumference: {circumference:.2f}')

Output:

Enter radius: 3
Area: 28.27, Circumference: 18.85

3. Check Even or Odd


Source Code:

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


if num % 2 == 0:
print('Even')
else:
print('Odd')

Output:
Enter a number: 7
Odd

4. Divisible by 5
Source Code:

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


if num % 5 == 0:
print('Divisible by 5')
else:
print('Not divisible by 5')

Output:

Enter a number: 10
Divisible by 5

5. Simple Interest
Source Code:

p = float(input('Principal: '))
r = float(input('Rate: '))
t = float(input('Time: '))
interest = (p * r * t) / 100
print(f'Simple Interest: {interest}')

Output:

Principal: 1000
Rate: 5
Time: 2
Simple Interest: 100.0

6. Greatest of Three Numbers


Source Code:

a = int(input('Enter a: '))
b = int(input('Enter b: '))
c = int(input('Enter c: '))
print('Greatest:', max(a, b, c))

Output:
Enter a: 10
Enter b: 25
Enter c: 15
Greatest: 25

7. Voting Age Verification


Source Code:

age = int(input('Enter age: '))


if age >= 18:
print('Eligible to vote')
else:
print('Not eligible to vote')

Output:

Enter age: 20
Eligible to vote

8. Leap Year Check


Source Code:

year = int(input('Enter year: '))


if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print('Leap year')
else:
print('Not a leap year')

Output:

Enter year: 2024


Leap year

9. Simple Calculator
Source Code:

op = input('Enter operator (+, -, *, /): ')


a = float(input('Num 1: '))
b = float(input('Num 2: '))
if op == '+': print(a+b)
elif op == '-': print(a-b)
elif op == '*': print(a*b)
elif op == '/': print(a/b)
Output:

Enter operator (+, -, *, /): +


Num 1: 5
Num 2: 3
8.0

10. Table of a Number


Source Code:

num = int(input('Enter number: '))


for i in range(1, 11):
print(f'{num} x {i} = {num * i}')

Output:

Enter number: 2
2x1=2
...
2 x 10 = 20

You might also like