win7安装python生成随机数代码分享

WBOY
Release: 2016-06-16 08:45:49
Original
1426 people have browsed it

复制代码 代码如下:

import random

def genrand(small, big) :
    return small + (big-small) * random.random()

def display(small, big) :
    return r'请输入上下限(默认%.2f~%.2f):' % (small, big)

big = 100
small = 0

while True :
    try :
        s = input(display(small, big)).strip()
        if s.lower() == 'exit' :
            break
        a = s.split()
        if a != [] :
            big = float(a[1])
            small = float(a[0])
        rand = genrand(small, big)
        print('(%.2f~%.2f): %.3f\n' % (small, big, rand))
    except :
        print('--Error--\n')

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template