{"id":25744,"date":"2021-12-04T09:19:54","date_gmt":"2021-12-04T03:49:54","guid":{"rendered":"https:\/\/python-programs.com\/?p=25744"},"modified":"2021-12-04T09:19:54","modified_gmt":"2021-12-04T03:49:54","slug":"python-program-for-multi-conditional-if-statement","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-multi-conditional-if-statement\/","title":{"rendered":"Python Program for Multi-Conditional If Statement"},"content":{"rendered":"

Python If Statement :<\/strong><\/p>\n

The ‘If’ statement is a conditional statement that is used to determine whether or not a specific expression is true. The program control first checks the condition written with’if ‘, and if the condition is true, the if block is executed. Otherwise, the program control is transferred to the else block and executed.<\/p>\n

Syntax:<\/strong><\/p>\n

if(condition):\r\n    block code 1\r\nelse:\r\n    block code 2<\/pre>\n

If the condition is met, block code 1 is executed. If this is not the case, block code 2 is executed.<\/p>\n

We all use a basic if statement, which is an if statement with only one condition. This is used to compare one variable to another or to determine whether a variable is true or false.<\/p>\n

For Example:<\/strong><\/p>\n

gvn_num = int(input(\"Enter some random number = \"))\r\n# condition to check whether the given number is even or odd.\r\nif((gvn_num % 2) == 0):\r\n    print(\"The given number is an Even Number\")\r\nelse:\r\n    print(\"The given number is an Odd Number\")\r\n<\/pre>\n

Output:<\/strong><\/p>\n

Enter some random number = 10\r\nThe given number is an Even Number<\/pre>\n

Multiple Conditions in If Statement<\/strong><\/p>\n

Multiple conditions can be used in a single if statement by using AND, OR, or BOTH.<\/p>\n

Syntax:<\/strong><\/p>\n

if ((condition1) AND\/OR (condition2)) :\r\n\u00a0 \u00a0 block code 1\r\nelse :\r\n\u00a0 \u00a0 block code 2<\/pre>\n

Program for Multi-Conditional If Statement<\/h2>\n