if 语句
if expression:
expr_true_suite
if 语句的 expr_true_suite 代码块只有当条件表达式 expression 结果为真时才执行,否则将继续执行紧跟在该代码块后面的语句。
单个 if 语句中的 expression 条件表达式可以通过布尔操作符 and,or和not 实现多重条件判断。
if 2 > 1 and not 2 > 3:
print('Correct Judgement!')
# Correct Judgement!
if - else 语句
if expression:
expr_true_suite
else:
expr_false_suite
temp = input("猜一猜小姐姐想的是哪个数字?")
guess = int(temp) # input 函数将接收的任何数据类型都默认为 str。
if guess == 666:
print("你太了解小姐姐的心思了!")
print("哼,猜对也没有奖励!")
else:
print("猜错了,小姐姐现在心里想的是666!")
print("游戏结束,不玩儿啦!")