输入一个数字,比较与系统内既定数字的大小:
a = 66
while True:
b = int(input('请输入目标数字(提示:在50——100之间):'))
if b == a:
print('你好您猜对了!')
break
elif b <= a:
print('不好意思,小了')
else :
print('对不起大了')
这样只能算是一个判断,没有游戏的趣味性,至少多给几次机会啊。于是又对代码进行了小小改进:
a = 66
b = int(input('请用5次机会,在50——100中猜出抽奖数字:'))
c = 0
d = 5
while True:
c += 1
e = 5 - c
if a == b and c <= d:
print('恭喜答对了')
print('您一共用了{}次机会'.format(c))
break
elif b <= a and c <=d:
print('猜错了,小了一点')
print('您还有{}次机会'.format(e))
b = int(input('请继续加油:'))
elif b >= a and c <=d:
print('猜错了,大了一点')
print('您还有{}次机会'.format(e))
b = int(input('请继续努力:'))
else:
print('抱歉,机会用光了。')
break
就是一个while循环加if条件判断的语句,现在想想当初也是年轻~~~~