|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
dice roll
hey, u know how u are
i need the script to make that dice roll program again...my msn is playing up.. |
|
#2
|
||||
|
||||
|
Code:
#!/usr/bin/env python
import rand
def getroll():
die = rand.rand() % 6 + 1
return die
die1 = getroll()
die2 = getroll()
print "Die 1: ", die1, " Die 2: ", die2, " Total: ", die1 + die2
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#3
|
||||
|
||||
|
You could've used
Code:
die = random.randint(1,6) ![]() |
|
#4
|
||||
|
||||
|
Infact Scorpi your dice role program wont work at all on newer versions of Python since the rand module no longer exists in the standard library.. What version of Python are you running ATM?
Mark. |
|
#5
|
||||
|
||||
|
Just for those who are interested, Python 1.5.2 was the last version of Python to support the rand module apparently. It seems to have been depreciated since even before version 2!
Quote:
It is still in Pythons doc's, in the "Undocumented Modules" part which simply says..Quote:
Take care, Mark. Last edited by netytan : October 30th, 2003 at 03:58 PM. |
|
#6
|
||||
|
||||
|
Actually, it happens that the box I tested the code snippet on is running Python 1.5.2 (on RH 7.1
). It's the only box I have lying around the office that has python on it. My boxes at home have later versions ![]() |
|
#7
|
||||
|
||||
|
Ah that explains it then
, i'd tell you to update but your one of the redhat guys and we don't wana break anything ..Well if were all in agreement you can do the dice thing like this mike: Code:
#!/usr/bin/env python
import random
#role the dice
die = random.randint(1, 6)
#deside what to do depending on th value of the die. i.e 1, 2, 3, 4, 5, 6
if die == 1:
print 'do soemthing when random is', random
if die == 2:
print 'do soemthing else when it is', random
else:
print 'do this if random is', random
well fix it then ,have fun, Mark. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > dice roll |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|