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

Class9labprgm Solutions

Uploaded by

9epresentations
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)
8 views4 pages

Class9labprgm Solutions

Uploaded by

9epresentations
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

1) Program to take two integers as input and find their sum:

# Taking two integers as input


num1 = int(input("Enter first integer: "))
num2 = int(input("Enter second integer: "))

# Calculating the sum


sum_result = num1 + num2

# Displaying the result


print("Sum of the numbers is:", sum_result)

### 2) Program to take length and width of a rectangle as input and find its perimeter and
area:

# Taking length and width as input


length = float(input("Enter length of the rectangle: "))
width = float(input("Enter width of the rectangle: "))

# Calculating perimeter and area


perimeter = 2 * (length + width)
area = length * width

# Displaying the results


print("Perimeter of the rectangle:", perimeter)
print("Area of the rectangle:", area)

### 3) To calculate average marks of 3 subjects:


# Taking marks as input
marks1 = float(input("Enter marks for subject 1: "))
marks2 = float(input("Enter marks for subject 2: "))
marks3 = float(input("Enter marks for subject 3: "))

# Calculating average
average = (marks1 + marks2 + marks3) / 3

# Displaying the result


print("Average marks:", average)

### 4) To calculate area of a triangle with base and height:


# Taking base and height as input
base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))

# Calculating area
area = 0.5 * base * height

# Displaying the result


print("Area of the triangle:", area)

### 5) To convert length given in kilometers to meters:


# Taking kilometers as input
kilometers = float(input("Enter distance in kilometers: "))

# Converting kilometers to meters


meters = kilometers * 1000

# Displaying the result


print(f"{kilometers} kilometers is equal to {meters} meters.")

6) To find if a number is odd or even:


# Taking a number as input
num = int(input("Enter a number: "))

# Checking if the number is odd or even


if num % 2 == 0:
print(f"{num} is even.")
else:
print(f"{num} is odd.")

### 7) To check if a number is divisible by 2:


# Taking a number as input
num = int(input("Enter a number: "))

# Checking divisibility by 2
if num % 2 == 0:
print(f"{num} is divisible by 2.")
else:
print(f"{num} is not divisible by 2.")

### 8) To check by age if user is eligible to vote:


# Taking age as input
age = int(input("Enter your age: "))

# Checking eligibility to vote


if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")

### 9) To print the table of 5 upto 5 terms:

# Printing the table of 5 up to 5 terms


for i in range(1, 6):
print(f"5 x {i} = {5 * i}")

### 10) To print first 10 natural numbers:


# Printing first 10 natural numbers
for i in range(1, 11):
print(i)

### 11) To find speed of a vehicle with distance and time as input:
# Taking distance and time as input
distance = float(input("Enter distance (in km): "))
time = float(input("Enter time (in hours): "))

# Calculating speed
speed = distance / time

# Displaying the result


print(f"Speed of the vehicle is: {speed} km/h")

### 12) To find the perimeter and semiperimeter of a triangle:


# Taking sides of the triangle as input
side1 = float(input("Enter side 1 of the triangle: "))
side2 = float(input("Enter side 2 of the triangle: "))
side3 = float(input("Enter side 3 of the triangle: "))

# Calculating perimeter and semiperimeter


perimeter = side1 + side2 + side3
semiperimeter = perimeter / 2

# Displaying the results


print(f"Perimeter of the triangle: {perimeter}")
print(f"Semi-perimeter of the triangle: {semiperimeter}")
### 13) To calculate the discount for the price given by the user:

# Taking original price and discount percentage as input


original_price = float(input("Enter the original price: "))
discount_percentage = float(input("Enter the discount percentage: "))

# Calculating discount
discount = (discount_percentage / 100) * original_price
final_price = original_price - discount

# Displaying the results


print(f"Discount is: {discount}")
print(f"Final price after discount: {final_price}")

### 14) To print first 10 even numbers:


# Printing first 10 even numbers
for i in range(2, 21, 2):
print(i)

### 15) To print odd numbers up to n:


# Taking the upper limit n as input
n = int(input("Enter the value of n: "))

# Printing odd numbers up to n


for i in range(1, n + 1, 2):
print(i)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy