|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
改进猜数字的游戏:
1.增加提示,猜的数字是大了还是小了
2.用户可以有3此机会
3.用户要猜的数字不能是固定不变得
===========================================================
import random
print ('--------Guess the number i set--------')
num = random.randint(1,10)
for i in range (0,2 +1):
print ('Please input the number:')
tem = input()
guess = int(tem)
if guess != num:
if guess < num:
print('Input number is low,input again!')
else:
print('Input number is big,input again!')
print('Input wrong,you got three chances totaly.')
else:
print ('You get the correct number\n')
print ('no any award though you correct')
break
print ('Game over!^-^')
================= RESTART: E:\Python\练习题\guess the number.py =================
--------Guess the number i set--------
Please input the number:
7
You get the correct number
no any award though you correct
Game over!^-^
>>>
================= RESTART: E:\Python\练习题\guess the number.py =================
--------Guess the number i set--------
Please input the number:
3
Input wrong,you got three chances totaly.
Input number is low,input again!
Please input the number:
6
You get the correct number
no any award though you correct
Game over!^-^
>>>
================= RESTART: E:\Python\练习题\guess the number.py =================
--------Guess the number i set--------
Please input the number:
5
Input wrong,you got three chances totaly.
Input number is low,input again!
Please input the number:
9
Input wrong,you got three chances totaly.
Input number is low,input again!
Please input the number:
7
Input wrong,you got three chances totaly.
Input number is low,input again!
Game over!^-^
>>>
================= RESTART: E:\Python\练习题\guess the number.py =================
--------Guess the number i set--------
Please input the number:
1
Input number is low,input again!
Input wrong,you got three chances totaly.
Please input the number:
2
Input number is low,input again!
Input wrong,you got three chances totaly.
Please input the number:
3
Input number is low,input again!
Input wrong,you got three chances totaly.
Game over!^-^
>>>
|
|