simple question. is it possible to write a script that rolls a six sided dice?
if this is possible, is it possible to tell it to roll the six sided dice 4 times and ignore the dice that rolled the lowest score?
if you want to know, i am working on a script to create a dungeons and dragons character :)
4 4119
simple question. is it possible to write a script that rolls a six sided dice?
if this is possible, is it possible to tell it to roll the six sided dice 4 times and ignore the dice that rolled the lowest score?
if you want to know, i am working on a script to create a dungeons and dragons character :)
Ofcourse it is possible, python can do anything! You can use the random module. it has several functions having to do with anything random. Try this link: http://docs.python.org/lib/module-random.html bartonc 6,596
Recognized Expert Expert
simple question. is it possible to write a script that rolls a six sided dice?
if this is possible, is it possible to tell it to roll the six sided dice 4 times and ignore the dice that rolled the lowest score?
if you want to know, i am working on a script to create a dungeons and dragons character :)
Just search TheScripts for "python dice". There are plenty of examples of this solution.
Python. Of course it's possible :)
No claims that this is efficient/pretty/best practise it just does the job.
from random import randrange
diceroll = [0, 0, 0, 0] #initialise a holder for dice rolls
i = 0 #counter for number of rolls
while i < 4: #loop through a dice throw routine diceroll[i] = randrange(1,7)
i += 1 diceroll.sort() #sort lowest to highest
diceroll = diceroll[1:] #drop the lowest number
print diceroll
Joshua and others are right; of course it can be done! I've modified Joshua's code a bit... - diceroll = [] #initialise a holder for dice rolls
-
i = 0 #counter for number of rolls
-
for i in range(4): #loop through a dice throw routine
-
diceroll.append(randrange(1,7))
-
-
diceroll.sort() #sort lowest to highest
-
diceroll = diceroll[1:] #drop the lowest number
-
print diceroll
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Richard Shea |
last post by:
Hi - I've writing a Python script which has a query which looks like
this ...
select * from T where C1 not in (1,2,3)
.... C1 is a numeric column so elements of (1,2,3) must not be quoted
like this ('1','2','3') and of course they must not be quoted like
this ('1,2,3').
I'm using 'scanf' style substitution into the SQL, eg ...
|
by: Holger Joukl |
last post by:
You could use the str() builtin, returning the string representation of the
list object:
>>> params = (1, 2, 3)
>>> "select * from T where C1 not in %s" % str(params)
'select * from T where C1 not in (1, 2, 3)'
>>>
|
by: Evan Simpson |
last post by:
WEBoggle needs a new game board every three minutes. Boards take an
unpredictable (much less than 3min, but non-trivial) amount of time to
generate. The system is driven by web requests, and I don't want the
request that happens to trigger the need for the new board to have to
pay the time cost of generating it.
I set up a producer thread that does nothing but generate boards and put
them into a length-two Queue (blocking). At the rate...
|
by: AngleWyrm |
last post by:
I have created a new container class, called the hat.
It provides random selection of user objects, both with and without
replacement, with non-uniform probabilities. Uniform probabilities are a
degenerate case, and can also be stored.
Here's the web-page, with complete source, illustration, and example usage.
Take a look-see, and post your critique!
http://home.comcast.net/~anglewyrm/hat.html
|
by: Alfonso Morra |
last post by:
Hi,
I am writing a timer class that I want to be able to get to notify me
(via a callback func), when a specified interval has elapsed. I have
most of the timer functionality figured - however, I need to spawn a new
thread to carry out the "time watch" - and I need to do this in a cross
platform (Well Linux/Windows) way ...
Any help will be much appreciated. The code (snippet) follows below:
| |
by: Nils Magnus Englund |
last post by:
Hi,
I've made a HttpModule which deals with user authentication. On the first
request in a users session, it fetches data from a SQL Server using the
following code:
using (SqlConnection connection = new
SqlConnection(ConfigurationSettings.AppSettings))
{
|
by: mahurshi |
last post by:
I am new to c++ classes. I defined this "cDie" class that would return
a value between 1 and 6 (inclusive) It runs fine and gives no warnings
during compilation.
I was wondering if you guys can pick up any mistakes/"don't do"s from
this code:
#include <iostream>
#include <cstdlib>
|
by: rover8898 |
last post by:
Hello all,
I used setjmp() in a recent of program of mine (it is not completed, so
I have not the chance to test it out yet). I am not very profocient in
C coding as are some of my co-workers. They (my co-workers) say (with
vehement ardor ;) ) that the usage of setjmp() emplyoyed in function"C"
that was called from function "B" that was called from function "A"
that was called form the main(), will cause havoc in the stack. And it
makes...
|
by: WaterWalk |
last post by:
I've just read an article "Building Robust System" by Gerald Jay
Sussman. The article is here:
http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf
In it there is a footprint which says:
"Indeed, one often hears arguments against building exibility into an
engineered sys-
tem. For example, in the philosophy of the computer language Python it
is claimed:
\There should be one|and preferably only one|obvious...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |