if if elif
if elif else
两个不同的判断条件方法。
number = 6
guess = 0
print('数字猜谜游戏!')
while guess != number: #循环语句,如果猜不对就一直循环
guess = int(input('请输入你猜的数字'))
if guess == number:
print('恭喜,你猜对了')
elif guess < number:
print('猜的数字太小了...')
else:
print('猜的数字太大了...')
number = 6
guess = 0
print('数字猜谜游戏!')
while guess != number: #循环语句,如果猜不对就一直循环
guess = int(input('请输入你猜的数字'))
if guess == number:
print('恭喜,你猜对了')
if guess < number:
print('猜的数字太小了...')
elif guess > number:
print('猜的数字太大了...')
➜ pythoncode python3 holly_03_17.py
数字猜谜游戏!
请输入你猜的数字2
猜的数字太小了...
请输入你猜的数字8
猜的数字太大了...
请输入你猜的数字6
恭喜,你猜对了