Decision Making

Python Decision Making Statements


Decision making statements helps us in controlling flow of execution in programs. Decision making statements are also known as conditional statements.

Programming language executes program statements line by line. But, there are some situations in which we may not want to execute all statements written in programs. For example, in Python program to print Good Morning message, we print “Good morning” message when time is less than 12. In this program, we don't want to execute remaining statements displaying “Good Afternoon, Good Evening or Good Night” messages. In this situation Python Decision Making statement (if statement) helps us in controlling flow of execution. Let’s learn more about decision making statements.


Python Decision Making Statements


Python provides following decision making statements (also known as conditional statements):


Following Python practical will check whether entered number is positive or negative or zero. This program demonstrates the use of Python's nested if statement.

# Program will check whether entered number is positive or negative or zero.

number = int(input("Enter your number:"))

if number >= 0:
   if number == 0:
      print ("It's Zero.")
   else:
      print("It's Positive number.")
else:
   print("It's Negative number.")

Output of Program

Enter your number:5
It's Positive number.



No comments:

Post a Comment