Python3猜数字小游戏

简介: Python3猜数字小游戏

**项目要求
1:产生10000以内的随机数让用户猜
2:记录用户猜的次数以及时间并打印出来
3:提示用户所猜数字的大小**

#coding:utf-8
import random
import datetime
numbers=random.randint(1,10000)
times=0
start_time=datetime.datetime.now()
for i in range(10000):
    times = times + 1
    user_input=int(input("请输入数字:"))
    if user_input > numbers :
        print("输入的数值过大!请重新输入!")
    elif user_input == numbers :
        print("你猜中了!")
        print("你一共猜了",times,"次")
        end_time=datetime.datetime.now()
        print("一共花费时间",end_time-start_time)
        exit()
    elif user_input < numbers :
        print("输入的数值过小!请重新输入!")
exit()
目录
相关文章
|
1月前
|
人工智能 机器人 测试技术
【python】python小游戏——开心消消乐(源码)【独一无二】
【python】python小游戏——开心消消乐(源码)【独一无二】
|
1月前
|
Python
python小游戏4
python小游戏4
|
1月前
|
Python
python小游戏7
python小游戏7
|
1月前
|
Python
python小游戏6
python小游戏6
|
1月前
|
Python
python小游戏5
python小游戏5
|
1月前
|
Python
python小游戏1
python小游戏1
|
1月前
|
安全 C++ Python
小游戏实战-Python实现石头剪刀布+扫雷小游戏
小游戏实战-Python实现石头剪刀布+扫雷小游戏
52 0
|
1月前
|
数据可视化 安全 数据安全/隐私保护
使用Python做个可视化的“剪刀石头布”小游戏
使用Python做个可视化的“剪刀石头布”小游戏
51 0
|
1月前
|
Python
python小游戏3
python小游戏3
|
1月前
|
Python
python小游戏
python小游戏