Roll a six-sided die 6000 times. : random « Buildin Module « Python Tutorial

Python Tutorial
1. Introduction
2. Data Type
3. Statement
4. Operator
5. String
6. Tuple
7. List
8. Dictionary
9. Collections
10. Function
11. Class
12. File
13. Buildin Function
14. Buildin Module
15. Database
16. Regular Expressions
17. Thread
18. Tkinker
19. wxPython
20. XML
21. Network
22. CGI Web
23. Windows
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorial
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Python Tutorial » Buildin Module » random 
14. 11. 2. Roll a six-sided die 6000 times.
import random

frequency1 = 0
frequency2 = 0
frequency3 = 0
frequency4 = 0
frequency5 = 0
frequency6 = 0

for roll in range16001 ):       # 6000 die rolls
   face = random.randrange1)

   if face == 1:                    # frequency counted
      frequency1 += 1
   elif face == 2:
      frequency2 += 1
   elif face == 3:
      frequency3 += 1
   elif face == 4:
      frequency4 += 1
   elif face == 5:
      frequency5 += 1
   elif face == 6:
      frequency6 += 1
   else:                            # simple error handling
      print "should never get here!"

print "Face %13s" "Frequency"
print "   1 %13d" % frequency1
print "   2 %13d" % frequency2
print "   3 %13d" % frequency3
print "   4 %13d" % frequency4
print "   5 %13d" % frequency5
print "   6 %13d" % frequency6
14. 11. random
14. 11. 1. Random integers produced by randrange.
14. 11. 2. Roll a six-sided die 6000 times.
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.