Mine værktøjer
Du er her: Forside diverse filer til download mm. Random.py
Handlinger tilknyttet webside

Random.py

af adminSidst opdateret 10/07 2007 09:06

http://www.eksperten.dk/spm/785357

Klik her for at hente fil

Størrelse: 1.3 kB - Filtype text/python-source

Indhold af fil-indholdsobjekt

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import random
Page = """Content-type: text/html

<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Se og hent kildekoden <a target="_blank" href="http://www.databassen.dk:8090/bauerdata/python-program-eksempler/Random.py">her</a>

<hr>
<p><a href="Random.py">Ny liste</a></p>
<hr>
<table border="1"><td>%(liste)s</td></table>
<hr>
<b>Python er nemt, Python er sjovt.</b>
</html>
"""
from pprint import pprint
def Random( minDiff=5, maxDiff=12 , Min=1, Max=29, Repeats=60, Sort=False ):
    assert 0 < minDiff < maxDiff < Max
    assert 0 < Min < Max
    assert Min + minDiff * 2 < Max
    assert 0 < Repeats

    Set = range( Min, Max + 1 )
    Liste = []
    while len( Liste ) < Repeats:
        Tal = [ random.choice(Set) for i in range( 3 ) ]
        Tal.sort()
        (A1,A2,A3) = Tal
        highDif = A3 - A2
        lowDif = A2 - A1
        if not minDiff <= highDif <= maxDiff: continue
        if not minDiff <= lowDif  <= maxDiff: continue
        if highDif == lowDif: continue
        if Liste.count(Tal) == 0:
            Liste.append( Tal )
    if Sort:
        Liste.sort()
    return Liste

liste = "</td><td>".join( [ "%s %s %s" %  ( y[0] , y[1], y[2] )  for y in Random() ] )
print Page % vars() 
Relateret indhold
« august 2018 »
søn man tir ons tor fre lør
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Chat Rooms
Dyrk motion

Trim ballerup

 

Powered by Plone, the Open Source Content Management System