Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python combine if statements

# You need to wrap each test in brackets, then wrap the entire thing in brackets.
# Eg:
age = 18  
if ((age >= 8) and (age <= 12)):
    print("YOU ARE ALLOWED. WELCOME !")
else:
    print("SORRY ! YOU ARE NOT ALLOWED. BYE !")
    
# Broken down:
# Say I want to do these two tests: "age >= 8" and "age <= 12"
# First I need to wrap each test in brackets like so: (age >= 8) (age <= 12)
# Now join them with the word 'and': (age >= 8) and (age <= 12)
# Finally, wrap them together into an if statement: if ((age >= 8) and (age <= 12)):
# This can be used to chain many tests together.
#
# You can replace also replace 'and' with 'or'
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #python #combine #statements
ADD COMMENT
Topic
Name
7+5 =