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

Program-From-1 to 5

The document contains five programming tasks that involve basic conditional checks and calculations. These tasks include determining the possibility and type of a triangle based on angles, calculating profit or loss based on cost and selling prices, finding the greatest of three numbers, checking divisibility of a number by 3 and 5, and identifying leap years. Each task is accompanied by sample inputs and outputs, as well as code snippets to achieve the desired functionality.

Uploaded by

kalpanapriyam213
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)
3 views4 pages

Program-From-1 to 5

The document contains five programming tasks that involve basic conditional checks and calculations. These tasks include determining the possibility and type of a triangle based on angles, calculating profit or loss based on cost and selling prices, finding the greatest of three numbers, checking divisibility of a number by 3 and 5, and identifying leap years. Each task is accompanied by sample inputs and outputs, as well as code snippets to achieve the desired functionality.

Uploaded by

kalpanapriyam213
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

Question 1

Write a program to input three angles of a triangle and check whether a triangle is possible or not. If possible then
check whether it is an acute-angled triangle, right-angled or an obtuse-angled triangle otherwise, display 'Triangle
not possible'.

Sample Input: Enter three angles: 40, 50, 90

Sample Output: Right=angled Triangle

# Input three angles separated by comma

angles = input("Enter three angles: ") # Example input: 40, 50, 90

# Split input string and convert each angle to integer

angle_list = [int(angle.strip()) for angle in angles.split(',')]

# Assign angles to variables for clarity

a, b, c = angle_list

# Check if triangle is possible: sum of angles must be 180 and each angle > 0

if (a + b + c == 180) and (a > 0 and b > 0 and c > 0):

# Check for right-angled triangle (one angle == 90)

if a == 90 or b == 90 or c == 90:

print("Right-angled Triangle")

# Check for acute-angled triangle (all angles < 90)

elif a < 90 and b < 90 and c < 90:

print("Acute-angled Triangle")

# Otherwise, obtuse-angled (one angle > 90)

else:

print("Obtuse-angled Triangle")

else:

print("Triangle not possible")

Question 2

Write a program to input the cost price and the selling price of an article.

If the selling price is more than the cost price then calculate and display actual profit and

profit per cent otherwise, calculate and display actual loss and loss per cent.

If the cost price and the selling price are equal, the program displays the message 'Neither profit nor loss'.
# Input cost price and selling price from the user
cost_price = float(input("Enter the cost price: "))
selling_price = float(input("Enter the selling price: "))

# Check conditions and calculate profit or loss


if selling_price > cost_price:
profit = selling_price - cost_price
profit_percent = (profit / cost_price) * 100
print(f"Profit = {profit:.2f}")
print(f"Profit Percentage = {profit_percent:.2f}%")
elif selling_price < cost_price:
loss = cost_price - selling_price
loss_percent = (loss / cost_price) * 100
print(f"Loss = {loss:.2f}")
print(f"Loss Percentage = {loss_percent:.2f}%")
else:
print("Neither profit nor loss")

Question 3

Write a program to input three numbers and check whether they are equal or not.

If they are unequal numbers then display the greatest among them otherwise, display the message 'All the numbers
are equal'.

Sample Input: 34, 87, 61

Sample Output: Greatest number: 87

Sample Input: 81, 81, 81

Sample Output: All the numbers are equal.

# Input three numbers separated by comma


numbers = input("Enter three numbers: ") # Example input: 34, 87, 61

# Convert input string to a list of integers


num_list = [int(num.strip()) for num in numbers.split(',')]

# Assign numbers to variables for clarity


a, b, c = num_list
# Check if all numbers are equal
if a == b == c:
print("All the numbers are equal.")
else:
greatest = max(a, b, c)
print(f"Greatest number: {greatest}")

Question 4

Write a program to accept a number and check whether the number is divisible by 3 as well as 5. Otherwise, decide:

(a) Is the number divisible by 3 and not by 5?

(b) Is the number divisible by 5 and not by 3?

(c) Is the number neither divisible by 3 nor by 5?

The program displays the message accordingly.

# Accept input number from user


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

# Check divisibility conditions


if num % 3 == 0 and num % 5 == 0:
print("The number is divisible by both 3 and 5.")
elif num % 3 == 0 and num % 5 != 0:
print("The number is divisible by 3 but not by 5.")
elif num % 5 == 0 and num % 3 != 0:
print("The number is divisible by 5 but not by 3.")
else:
print("The number is neither divisible by 3 nor by 5.")

Question 5

Write a program to input year and check whether it is:

(a) a Leap year (b) a Century Leap year (c) a Century year but not a Leap year

Sample Input: 2000

Sample Output: It is a Century Leap Year.


# Input year from user
year = int(input("Enter a year: "))

# Check if it is a century year (divisible by 100)


if year % 100 == 0:
# Check if it is a century leap year (divisible by 400)
if year % 400 == 0:
print("It is a Century Leap Year.")
else:
print("It is a Century Year but not a Leap Year.")
else:
# For non-century years, check if divisible by 4 (leap year condition)
if year % 4 == 0:
print("It is a Leap Year.")
else:
print("It is not a Leap Year.")

You might also like