首页 > 其他 > 详细

猜数字问题

时间:2020-03-07 12:00:00      阅读:57      评论:0      收藏:0      [点我收藏+]

# 题目:猜数字问题,要求如下:
# ① 随机生成一个整数
# ② 猜一个数字并输入
# ③ 判断是大是小,直到猜正确
# ④ 判断时间
# 提示:需要用time模块、random模块
# 该题目不需要创建函数

 

import time

import random

play_it = input(‘do you want to play it.(\‘y\‘ or \‘n\‘)‘) # 询问是否参与游戏
while play_it == ‘y‘:
c = input(‘input a character:\n‘) # 输入参与游戏人物
i = random.randint(0,100)
print( ‘please input number you guess:\n‘)
a = time.time() # 记录开始时间
guess = int(input(‘input your guess:\n‘))
while guess != i:
if guess > i:
print( ‘please input a little smaller‘)
guess = int(input(‘input your guess:\n‘))
else:
print( ‘please input a little bigger‘)
guess = int(input(‘input your guess:\n‘))
b = time.time() # 记录结束时间
usedtime = b - a
print( ‘It took you %.2f seconds‘ % usedtime)
if usedtime < 15:
print( ‘you are very clever!‘)
elif usedtime < 25:
print( ‘you are normal!‘)
else:
print( ‘you are stupid!‘)
print( ‘Congradulations‘)
print( ‘The number you guess is %d‘ % i)
break
else:
print(‘hehe‘)

猜数字问题

原文:https://www.cnblogs.com/Lilwhat/p/12433010.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!