0% found this document useful (0 votes)
117 views

CH - 6 Making Decision in Phython Program Solution Copy Work-2

This document discusses making decisions in Python programs. It covers comparison operators like >, <, >=, <=, ==, and != that are used to evaluate conditions. Logical operators like and, or, and not are used to combine multiple conditions. Conditional statements like if, if-else, and elif are used to execute code based on whether conditions evaluate to True or False. The document also shows how to take input from the user in Python as strings, integers, or floats. It includes examples of 6 Python programs that demonstrate using comparison operators, conditional statements, and input to make decisions and solve problems.

Uploaded by

Aviral
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views

CH - 6 Making Decision in Phython Program Solution Copy Work-2

This document discusses making decisions in Python programs. It covers comparison operators like >, <, >=, <=, ==, and != that are used to evaluate conditions. Logical operators like and, or, and not are used to combine multiple conditions. Conditional statements like if, if-else, and elif are used to execute code based on whether conditions evaluate to True or False. The document also shows how to take input from the user in Python as strings, integers, or floats. It includes examples of 6 Python programs that demonstrate using comparison operators, conditional statements, and input to make decisions and solve problems.

Uploaded by

Aviral
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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