0% found this document useful (0 votes)
5 views3 pages

Assignment Python Solutions

The document contains a series of Python programming assignments that cover various concepts such as calculating square and cube of a number, area and perimeter of a rectangle, simple interest, and identifying Armstrong numbers. It also includes tasks for determining the type of triangle based on side lengths, analyzing a list of numbers for even and odd counts, and performing basic dictionary operations. Each assignment is presented with code snippets that demonstrate the required functionality.

Uploaded by

dhankharvaibhav2
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)
5 views3 pages

Assignment Python Solutions

The document contains a series of Python programming assignments that cover various concepts such as calculating square and cube of a number, area and perimeter of a rectangle, simple interest, and identifying Armstrong numbers. It also includes tasks for determining the type of triangle based on side lengths, analyzing a list of numbers for even and odd counts, and performing basic dictionary operations. Each assignment is presented with code snippets that demonstrate the required functionality.

Uploaded by

dhankharvaibhav2
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

ASSIGNMENT – Python Solutions

1. Square and Cube of a Number

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


print("Square =", n*n)
print("Cube =", n*n*n)

2. Area and Perimeter of Rectangle

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


b = float(input("Enter breadth: "))
print("Area =", l*b)
print("Perimeter =", 2*(l+b))

3. Simple Interest

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


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

4. Output

print(7+3*(7-4))
print(100-15*2)

5. Largest of Two Numbers

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


b = int(input("Enter second number: "))
print("Largest =", max(a, b))

6. Check Unit Digit Even or Odd

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


if n % 2 == 0:
print("Unit digit is Even")
else:
print("Unit digit is Odd")

7. Sum and Product of Digits

n = int(input("Enter a 3-digit number: "))


a = n // 100
b = (n // 10) % 10
c = n % 10
print("Sum =", a+b+c)
print("Product =", a*b*c)

8. Armstrong Numbers (100–999)

for n in range(100, 1000):


s = sum(int(d)**3 for d in str(n))
if s == n:
print(n)

9. Type of Triangle

a = int(input("Enter side 1: "))


b = int(input("Enter side 2: "))
c = int(input("Enter side 3: "))

if a == b == c:
print("Equilateral Triangle")
elif a == b or b == c or a == c:
print("Isosceles Triangle")
else:
print("Scalene Triangle")

10. List of 10 Numbers Analysis

nums = []
for i in range(10):
[Link](int(input("Enter number: ")))

even = [n for n in nums if n % 2 == 0]


odd = [n for n in nums if n % 2 != 0]

print("Count of even numbers:", len(even))


print("Count of odd numbers:", len(odd))
print("Sum of even numbers:", sum(even))
print("Sum of odd numbers:", sum(odd))
print("Divisible by 10:", len([n for n in nums if n % 10 == 0]))

11. Dictionary Operations

student = {"name": "Rahul", "age": 16, "grade": "a"}

student["grade"] = "a+"
print("Age:", student["age"])

student["subject"] = "computer science"


print(student)

You might also like