条件语句:
if
if … else
if … elif … else
if语句的格式:
if 条件:
条件成立要执行的语句
print(1)
print(2)
print(3)
# 4, 5, 6 有条件打印
result = input('请输入(y/n):')
if result == 'y':
print(4)
print('over~~~~')
elif result == 'n':
print(5)
print('over~~~~')
else:
print(6)
print('over~~~')
# 随机数
import random
a = random.randint(1,10)
print(a)
quess = input('请输入你猜的数:')
if a == int(quess):
print('恭喜猜对了!')
elif a > int(quess):
print('猜小了!')
else:
print('猜大了!')