Академический Документы
Профессиональный Документы
Культура Документы
Selection statements
if statement
The if statement is used to test a particular condition and if the
condition is true, it executes a block of code known as if-block.
if-else statement
The if-else statement provides an else block combined with the if statement
which is executed in the false case of the condition.
If the condition is true, then the if-block is executed. Otherwise, the else-block
is executed.
Ladder if’s statement
MAINGATE
GATE1 BROWN GATE1 RED GATE1 GREEN GATE2 BROWN GATE2 RED GATE2 GREEN
OPEN OPEN OPEN OPEN OPEN OPEN
Q1. Take values of length and breadth of a rectangle from user and
check if it is square or not.
Property of a triangle
Step by step descriptive logic to check whether a triangle can be formed or not, if angles are
given.
1.Input all three angles of triangle in some variable say angle1, angle2 and angle3.
2.Find sum of all three angles, store sum in some variable say sum = angle1 + angle2
+ angle3.
3.Check if(sum == 180) then, triangle can be formed otherwise not. In addition,
make sure angles are greater than 0 i.e. check condition for angles if(angle1 != 0 &&
angle2 != 0 && angle3 != 0)
program to check whether triangle is equilateral, scalene or isosceles
Properties of triangle
•A triangle is said Equilateral Triangle, if all its sides are equal. If a,
b, c are three sides of triangle. Then, the triangle is equilateral
only if a == b == c.
•A triangle is said Isosceles Triangle, if its two sides are equal. If a,
b, c are three sides of triangle. Then, the triangle is isosceles if
either a == b or a == c or b == c.
•A triangle is said Scalene Triangle, if none of its sides are equal.
Logic to check equilateral, scalene or isosceles triangle
note500=1250//500 = 2
next is
amt=amt - (note500 * 500 )
amt = 1250 -(2 * 500 )
amt = 1250 -(1000)
amt = 250
Syntax:
if expression1:
statement(s)
elif expression2:
statement(s)
elif expression3:
statement(s)
else:
statement(s)
Write a program to input month number and print number of days in that
month.