1variable_name = input("y/n? >> ")
2if variable_name == "y":
3 print("That's good! :) ")
4# note the double equal signs. only a single equal sign will receive a Syntax error blah blah blah message.
5elif variable_name == "n":
6 print("That's bad! :( ")
7else:
8 print("You blow up for not following my instructions. Detention forever and get lost!")
1# The if,elif,else statements check if something is True
2# example
3if 10 > 5:
4 print("Ten is greater than five")
5
6#but let's say we write
7if 10 < 5:
8 print("Ten is less than five")
9#then this condition wouldn't be true
10#so we create an "else" statement
11if 10 < 5:
12 print("Ten is less than five")
13else:
14 print("Ten is greater than five")
15
16#this will print "Ten is greater than five"
17# because in the if statement it checks if something is true
18# we wrote 'if 10 < 5' and it's not true
19# so in case the 'if' condition evaluates to false
20# it executes another command
21
22#now, the 'elif' statement
23# this will check for another thing after the if statement
24#example
25if 10 < 5:
26 print("Ten is less than five")
27elif 10 > 5:
28 print("Ten is greater than five")
29# here we check if 10 is less than five
30# then the statement evaluated to false because 10 is greater than 5
31# so the program checked with the 'elif' (that means 'Else if')
32# if the statement was true, and it was so it executed the command
33
34#we can add as many elif statements as we want in our program
35# but they always need to start with an 'if' statement
36# and we can make only ONE 'else' statement at the end
37# let's add an 'else' statement to the previous program
38if 10 < 5:
39 print("Ten is less than five")
40elif 10 > 5:
41 print("Ten is greater than five")
42else:
43 print("Ten isn't greater or less than five")
44# in this case it will print 'Ten is greater than five'
45# hope this helped
1#a statement that checks if a condition is correct
2#example:
3x=5
4if x == 5:
5 print("x is 5")
6else:
7 print("x is not 5")
1if my_condition:
2 # Do some stuff
3 print("Hello You!")
4else:
5 # Do some stuff
6 print("Hello World!")
1a = 200
2b = 33
3if b > a:
4 print("b is greater than a")
5else:
6 print("b is not greater than a")
1water = input('Does your creature live underwater?')
2if water == 'yes':
3 print('Your creature lives underwater')
4else:
5 print('Your creature does not live underwater')