实例介绍Python2随机数列生成器


本文摘自php中文网,作者巴扎黑,侵删。

这篇文章主要介绍了Python2随机数列生成器,结合简单实例形式分析了Python基于random模块操作随机数的相关实现技巧,需要的朋友可以参考下

本文实例讲述了Python2随机数列生成器。分享给大家供大家参考,具体如下:


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

#filename:randNumber.py

import random

while True:

  try:

    row=int(raw_input('Enter the rows:'))

    cols=int(raw_input('then Enter the cols:'))

    minNum=int(raw_input('then Enter the minNumber:'))

    maxNum=int(raw_input('then Enter the maxNumber:'))

    r=0

    while r<row:

      line=''

      c=0

      while c<cols:

        s=random.randint(minNum,maxNum)

        line+=str(s)

        line+='  '

        c+=1

      r+=1

      print(line)

  except ValueError as err:

    print err

以上就是实例介绍Python2随机数列生成器的详细内容,更多文章请关注木庄网络博客!!

相关阅读 >>

Python运维学什么

numpy实现合并多维矩阵、list的扩展方法

如何用Python检查密码的有效性

Python输出语句如何写

Python中如何搭建虚拟环境?Python搭建虚拟环境的步骤

Python找工作难吗

Python中注释一般为什么颜色

r在Python中表示什么意思

Python中的mkdir方法怎么用

pandas技巧之 详解dataframe中的apply与applymap方法

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...