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

terning.py

af adminSidst opdateret 27/10 2007 09:52

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

Klik her for at hente fil

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

Indhold af fil-indholdsobjekt

#!/usr/bin/env python
"""Terninge kast"""
import cgi
import cgitb
# cgitb.enable()

Page = """Content-type: text/html

<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Tryk på terningen så kastes de igen
<p><a href="terning.py"><img src="/terninger/dice5.gif" /></a></td></p>
Se og hent kildekoden <a target="_blank" href="http://www.databassen.dk:8090/bauerdata/python-program-eksempler/terning.py">her</a>
<hr>
<table>
<td><img src="/terninger/dicewite%d.jpg" /></td>
<td><img src="/terninger/dicewite%d.jpg" /></td>
<td><img src="/terninger/dicewite%d.jpg" /></td>
<td><img src="/terninger/dicewite%d.jpg" /></td>
<td><img src="/terninger/dicewite%d.jpg" /></td>
</table>
<hr>
<table>
<thead>Statestik
<tr><th>Øjne</th><th>Antal</th><th>Fordeling</th></tr>
</thead>
<tr><td>%d</td><td align="right">%d</td><td align="right">%f</td> </tr>
<tr><td>%d</td><td align="right">%d</td><td align="right">%f</td> </tr>
<tr><td>%d</td><td align="right">%d</td><td align="right">%f</td> </tr>
<tr><td>%d</td><td align="right">%d</td><td align="right">%f</td> </tr>
<tr><td>%d</td><td align="right">%d</td><td align="right">%f</td> </tr>
<tr><td>%d</td><td align="right">%d</td><td align="right">%f</td> </tr>
<tr><td><b>Ialt</b></td><td align="right">%d</td></tr>
</table>
<hr>
<b>Python er nemt, Python er sjovt.</b>
<img src="/terninger/dilbert.gif">
</html>
"""

import random
import pickle

def add( x, y ): return x + y

statFile="../htdocs/terninger/statestik.pickle"
init = False
if init:
    statestik={1:0,2:0,3:0,4:0,5:0,6:0}
    f=open(statFile,"wb")
    pickle.dump(statestik,f)

f = open( statFile, "rb" )
statestik = pickle.load(f)
slag = [ random.choice(range(6))+1 for x in range(5) ]
for s in slag:
    statestik[ s ] += 1 
f=open(statFile,"wb")
pickle.dump(statestik,f)
f.close()
Stat = statestik.items()
Stat.sort()
ialt = sum( statestik.values() )
data = list( [ (x,y,float(y)/ialt) for x,y in Stat ] )
params = tuple(slag) + reduce( add, data ) + (ialt,)
print Page % params
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