Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Chapter 6

Making Decision In Python

Using comparison operator :-


The comparison operators in Python are used to make decisions
Comparison operator are of 6 types
1. Greater than (>)
2. Less than (<)
3. Greater than and equal to (>=)
4. Less than and equal to (<= )
5. Equal to (==)
6. Not equal to (!=)

Logical operator :-
If we need to combine more than one condition then we use these operator (and , or , not ).

Making decision on situation (conditional statement)


Conditional statements are represented in many forms as listed below
a). if statement :-
b). if else statement:-
c). elif statement :-

Taking Input From User

1. Taking string as input


Syntax
Variable name = input (“statement”)

2. Taking integer as input


Syntax
Variable name= int(input(“statement”))

3. Taking float as input


Syntax
Variable name = float(input(“statement”))
COPY WORK

Program 1. Write a program to find that the given number is even or odd ?
Solution :- number = int(input(“Enter the number “))
If number%2==0:
print(“The number is even ”)
else :
print(“ The number is odd”)

Program 2. Write a program to add two numbers and print result (result = A+B)?
Solution :- A= int(input(“Enter number A”))
B = int(input(“Enter number B”))
Result = A+B
print= (“Result”,Result)

Program 3. Write a program to find out that number 1 is greater or smaller than number 2 ?
Solution :- number1= int(input(“Enter the number 1”))
number2 = int(input(“Enter the number 2”))
if (number1 > number2 ):
print(number1, “ is greater than”,number2)
else:
print(number1, “ is smaller than”,number2)

Program 4. Write a program to find out that the number is negative , positive or zero ?
Solution :- number = int (input(“Enter the number ”))
if (number >0):
print(“ The number is positive”)
elif( number<0):
print(“The number is negative”)
else :
print(“The number is zero”)

Program 5. Write a program to find out square root of the given number ?
Solution :- number = int(input(“Enter the number” ))
print(“The square root of the number entered is :”,number**2)

Program 6. Write a program to calculate the area of the square field , first enter the length of the
square?
Solution :- length = int(input(“enter the square”))
area = length*length
print(“area of a square :”, area)

You might also like