python编程—猜数字小游戏
题目及要求:猜数字游戏
1.系统随机生成一个1~100的数字;
2.用户共有5次机会猜;
3.如果用户猜测数字大于系统给出的数字,打印"too big"
4.如果用户猜测数字小于系统给出的数字,打印"too small"
5.如果用户猜测的数字等于系统给出的数字,打印"Right",
并退出循环
完整代码如下:
"""
# _*_coding:utf-8_*_
Name:caishuzi.py
Date:1/14/19
Author:westos-sql
Connect:[email protected]
Desc:...
"""
import random
Number = random.randint(1, 100)
print('Begin Guess You have five chance to play!')
count = 1
while count < 6:
GuessNumber = int(input('Please input GuessNumber: '))
if GuessNumber == Number:
print('Right')
break
elif GuessNumber > Number:
print('too big')
else:
print('too small')
count += 1
print('You have %d chance' % (6 - count))
print('SysNumber is %d' % Number)
猜数字结果如下:
多次尝试后,终于猜对了