Sth about Python 01

1.Conditionals & Control Flow

记住if后面要加冒号:

def using_control_once():
if True:
return "Success #1"

def using_control_again():
if True:
return "Success #2"

print using_control_once()
print using_control_again()

if else

def black_knight():
if answer == "'Tis but a scratch!":
return True
else:
return False # Make sure this returns False

def french_soldier():
if answer == "Go away, or I shall taunt you a second time!":
return True
else:
return False # Make sure this returns False

if elif

def greater_less_equal_5(answer):
if answer > 5:
return 1
elif answer < 5:
return -1
else:
return 0

print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)

all of the conditions

Make sure that the_flying_circus() returns True

def the_flying_circus():
if 2 < 3: # Start coding here!
# Don't forget to indent
return True
# the code inside this block!
elif 2 ==3:
# Keep going here.
return False
# You'll want to add the else statement, too!

else :
    return 'Unbelievable'

你可能感兴趣的:(Sth about Python 01)