# if.py
pwd = input('What is the password? ')
if pwd == 'apple':
print('Logging on ...')
else:
print('Incorrect password.')
 
 
运行结果:
>>>
What is the password? banana
Incorrect password.
>>>
What is the password? apple
Logging on ...
 
 
--elif
if 条件:
表达式
elif 条件:
表达式
else:
表达式
 
--条件表达式
# if1.py
food = input('What is your favorite food? ')
reply = 'Yes' if food == 'apple' else 'No'
print(reply)
 
运行结果:
>>>
What is your favorite food? apple
Yes
>>>
What is your favorite food? banana
No
posted on 2017-02-06 20:07  john2017  阅读(108)  评论(0编辑  收藏  举报