{"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 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 Output:<\/strong><\/p>\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 1)Using AND<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n 2) Using OR<\/strong><\/p>\n When you want at least one condition to be satisfied, you use the OR condition.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n 1)Using AND\u00a0<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n 2) Using OR<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Python If Statement : 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 …<\/p>\nif(condition):\r\n block code 1\r\nelse:\r\n block code 2<\/pre>\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
Enter some random number = 10\r\nThe given number is an Even Number<\/pre>\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
\n
Method #1: Using If statement (Static Input)<\/h3>\n
\n
# Give the age as static input and store it in a variable.\r\ngvn_age = 32\r\n# Give the experience as static input and store it in another variable.\r\ngvn_expernce = 5\r\n# Check if the given age is greater than 25 and less than 55 and experience is\r\n# greater than 3 using the if conditional statement\r\nif (gvn_age > 25 and gvn_age < 55) and (gvn_expernce > 3):\r\n # If it is true, then print \"congrats you are selected\".\r\n print(\"congrats you are selected\")\r\nelse:\r\n # Else print \"You are not qualified sorry\".\r\n print(\"You are not qualified sorry\")\r\n<\/pre>\n
congrats you are selected<\/pre>\n
\n
# Give the number as static input and store it in a variable.\r\ngvn_num = 45\r\n# Get the remainder by dividing the given number by 10 and store it in another\r\n# variable.\r\nremaindr = gvn_num % 10\r\n# Check if the above-obtained remainder is equal to 0 or 5 using the if\r\n# conditional statement and or condition.\r\nif (remaindr == 0) or (remaindr == 5):\r\n #If it is true, then print \"The given number is divisible by 5\".\r\n print(\"The given number{\", gvn_num, \"} is divisible by 5\")\r\nelse:\r\n #Else, print\u00a0\"The given number is NOT divisible by 5\".\r\n print(\"The given number{\", gvn_num, \"} is NOT divisible by 5\")\r\n<\/pre>\n
The given number{ 45 } is divisible by 5<\/pre>\n
Method #2: Using If statement (User Input)<\/h3>\n
\n
# Give the age as user input using the int(input()) function and store it in a variable.\r\ngvn_age = int(input(\"Enter some random number(age) = \"))\r\n# Give the experience as user input using the int(input()) function and \r\n# store it in another variable.\r\ngvn_expernce = int(input(\"Enter some random number(experience) = \"))\r\n# Check if the given age is greater than 25 and less than 55 and experience is\r\n# greater than 3 using the if conditional statement\r\nif (gvn_age > 25 and gvn_age < 55) and (gvn_expernce > 3):\r\n # If it is true, then print \"congrats you are selected\".\r\n print(\"congrats you are selected\")\r\nelse:\r\n # Else print \"You are not qualified sorry\".\r\n print(\"You are not qualified sorry\")\r\n<\/pre>\n
Enter some random number(age) = 22\r\nEnter some random number(experience) = 3\r\nYou are not qualified sorry<\/pre>\n
\n
# Give the number as user input using the int(input()) function and store it in a variable.\r\ngvn_num = int(input(\"Enter some random number = \"))\r\n# Get the remainder by dividing the given number by 10 and store it in another\r\n# variable.\r\nremaindr = gvn_num % 10\r\n# Check if the above-obtained remainder is equal to 0 or 5 using the if\r\n# conditional statement and or condition.\r\nif (remaindr == 0) or (remaindr == 5):\r\n #If it is true, then print \"The given number is divisible by 5\".\r\n print(\"The given number{\", gvn_num, \"} is divisible by 5\")\r\nelse:\r\n #Else, print\u00a0\"The given number is NOT divisible by 5\".\r\n print(\"The given number{\", gvn_num, \"} is NOT divisible by 5\")\r\n<\/pre>\n
Enter some random number = 28\r\nThe given number{ 28 } is NOT divisible by 5<\/pre>\n","protected":false},"excerpt":{"rendered":"