Answers for "if else program in python"

11

if else python

# IF ELSE ELIF 

print('What is age?')
age = int(input('number:')) # user gives number as input
if age > 18:
    print('go ahead drive')
elif age == 18:
    print('come personaly for test')
else:
    print('still underage')
Posted by: Guest on August-12-2020
5

python if else

# The if,elif,else statements check if something is True
# example
if 10 > 5:
	print("Ten is greater than five")

#but let's say we write
if 10 < 5:
	print("Ten is less than five")
#then this condition wouldn't be true
#so we create an "else" statement
if 10 < 5:
	print("Ten is less than five")
else:
  	print("Ten is greater than five")

#this will print "Ten is greater than five"
# because in the if statement it checks if something is true
# we wrote 'if 10 < 5' and it's not true
# so in case the 'if' condition evaluates to false
# it executes another command

#now, the 'elif' statement
# this will check for another thing after the if statement
#example
if 10 < 5:
  	print("Ten is less than five")
elif 10 > 5:
	print("Ten is greater than five")
# here we check if 10 is less than five
# then the statement evaluated to false because 10 is greater than 5
# so the program checked with the 'elif' (that means 'Else if')
# if the statement was true, and it was so it executed the command

#we can add as many elif statements as we want in our program
# but they always need to start with an 'if' statement
# and we can make only ONE 'else' statement at the end
# let's add an 'else' statement to the previous program
if 10 < 5:
  	print("Ten is less than five")
elif 10 > 5:
	print("Ten is greater than five")
else:
  	print("Ten isn't greater or less than five")
# in this case it will print 'Ten is greater than five'
# hope this helped
Posted by: Guest on September-24-2020
2

if statement python

#a statement that checks if a condition is correct
#example:
x=5
if x == 5:
  print("x is 5")
else:
  print("x is not 5")
Posted by: Guest on November-20-2020
6

python if elif

num = 20
if num > 30:
  print("big")
elif num == 30:
  print("same")
else:
  print("small")
#output: small
Posted by: Guest on May-09-2020
1

else if python

name = input("What's your name? n") # Asks user for a name

# Following if order:
# first program checks if the if is true
# next program lists down the elifs (or else ifs) in the order 
# in which they are listed
# Lastly, if there is an else, program does whatever is inside
# of there.

if name == "Aguy12": # First checks if they answered "Aguy12"
  print("Wait a second...")
elif name == "Aguy11": # Then checks if they answered with "Aguy11"*
  print("Now that's definitely not true")
else: # If none of those are true greets the person accordingly
  print(f"Hello, {name}!")
  
# * ONLY IF THE IF STATEMENT IS NOT TRUE
Posted by: Guest on January-23-2021
1

if else python

if condition:
   result
elif condition:
   result
else:
   result
Posted by: Guest on January-11-2021

Python Answers by Framework

Browse Popular Code Answers by Language