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

YashKumar Python Final

The document contains Python code for two practical exercises: calculating the area of a rectangle, square, or triangle, and checking if a number is a palindrome or an Armstrong number. The area function prompts the user for dimensions and computes the area based on the selected shape. The check_number function evaluates a user-input number for palindrome and Armstrong properties, providing relevant outputs.

Uploaded by

STUDY FOREVER
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 views2 pages

YashKumar Python Final

The document contains Python code for two practical exercises: calculating the area of a rectangle, square, or triangle, and checking if a number is a palindrome or an Armstrong number. The area function prompts the user for dimensions and computes the area based on the selected shape. The check_number function evaluates a user-input number for palindrome and Armstrong properties, providing relevant outputs.

Uploaded by

STUDY FOREVER
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
You are on page 1/ 2

Python Practical File - Yash Kumar (Class

12)
1. Area of Rectangle, Square and Triangle
def area():
print("1. Rectangle\n2. Square\n3. Triangle")
ch = int(input("Enter your choice: "))
if ch == 1:
l = float(input("Enter length: "))
b = float(input("Enter breadth: "))
print("Area of Rectangle =", l * b)
elif ch == 2:
s = float(input("Enter side: "))
print("Area of Square =", s * s)
elif ch == 3:
b = float(input("Enter base: "))
h = float(input("Enter height: "))
print("Area of Triangle =", 0.5 * b * h)
else:
print("Invalid choice")
area()

Output:
Enter your choice: 1
Enter length: 5
Enter breadth: 4
Area of Rectangle = 20.0

2. Palindrome or Armstrong
def check_number():
num = int(input("Enter number: "))
rev = int(str(num)[::-1])
arm = sum([int(d)**3 for d in str(num)])
if num == rev:
print("Palindrome")
else:
print("Not Palindrome")
if num == arm:
print("Armstrong")
else:
print("Not Armstrong")
check_number()
Output:
Enter number: 121
Palindrome
Not Armstrong

You might also like