dice

Generate a matrix of all possible outcomes for throwing n dice (ignoring order)

送分小仙女□ 提交于 2019-12-05 00:30:05
问题 In cases where order does matter, it's rather easy to generate the matrix of all possible outcomes. One way for doing this is using expand.grid as shown here. What if it doesn't? If I'm right, the number of possible combinations is (S+N-1)!/S!(N-1)! , where S is the number of dice, each with N sides numbered 1 through N. (It is different from the well known combinations formula because it is possible for the same number to appear on more than one dice). For example, when throwing four six

python掷骰子猜大小游戏

非 Y 不嫁゛ 提交于 2019-12-04 23:20:58
完成猜大小游戏 规则如下:   投掷3个骰子,如果3个骰子之和小于10为小,大于10为大 步骤分解: 请用户输入大或小(用0,1代替) 投掷3个骰子,使用random库中的randint函数生成骰点大小,并依次输出骰点 计算骰点大小,判断用户输赢,并给出结果 代码如下: import random # 筛子的定义部分 图视化输出骰子 dice_tpl = ''' \ ┌───┐ , ┌───┐, ┌───┐, ┌───┐, ┌───┐, ┌───┐ │ │ , │ ● │, │● │, │● ●│, │● ●│, │● ●│ │ ● │ , │ │, │ ● │, │ │, │ ● │, │● ●│ │ │ , │ ● │, │ ●│, │● ●│, │● ●│, │● ●│ └───┘ , └───┘, └───┘, └───┘, └───┘, └───┘''' dice_lines = dice_tpl.split( '\n' ) #根据 \n 拆分 for m in range( 5 ): dice_lines[m] = dice_lines[m].split( ',' ) dice = [ '' , '' , '' , '' , '' , '' ] for n in range( 6 ): dice[n] = dice_lines[ 0 ][n] + '\n' + dice

PHP制作的掷色子点数抽奖游戏实例

泄露秘密 提交于 2019-12-04 17:39:44
PHP制作的掷色子点数抽奖游戏实例,通过掷色子点数来达到抽奖的效果,为抽奖活动增添一些趣味性。 我们将在html页面中写下如下的html结构代码,.wrap用来放置色子和提示信息,#prize则是用来放置奖品的。 1 <div class="demo"> 2 <div class="wrap"> 3 <div id="msg"></div> 4 <div id="dice"><span class="dice dice_1" id="dice1"></span> 5 <span class="dice dice_6" id="dice2"></span></div> 6 </div> 7 <ul id="prize"> 8 <li id="d_0"><img src="images/0.gif" alt="开始"></li> 9 <li id="d_1"><img src="images/1.gif" alt="现金100元"></li> 10 <li id="d_2"><img src="images/2.gif" alt="泰迪熊宝宝"></li> 11 <li id="d_3"><img src="images/7.gif" alt="谢谢参与"></li> 12 <li id="d_4"><img src="images/3.gif" alt="iphone 5s"><

Python dice simulation

最后都变了- 提交于 2019-12-04 16:01:20
问题 I'm a bit stuck on a homework question that simulates rolling dice. The question asks to create a function that returns a random integer value from 1 to 6, and to create a main program that asks the user how many dice to roll(must be limited to 5 dice), and calls the function to print the generated values. So far I have this: import random def dice(number_of_dice): for i in range(0,number_of_dice): return random.randint(1,6) number_of_dice = input("How many dice would you like to roll? ")

Python dice simulation

假如想象 提交于 2019-12-03 09:10:49
I'm a bit stuck on a homework question that simulates rolling dice. The question asks to create a function that returns a random integer value from 1 to 6, and to create a main program that asks the user how many dice to roll(must be limited to 5 dice), and calls the function to print the generated values. So far I have this: import random def dice(number_of_dice): for i in range(0,number_of_dice): return random.randint(1,6) number_of_dice = input("How many dice would you like to roll? ") while number_of_dice >5: number_of_dice = input("You may only have a limit of 5 dice, enter a number under

Evaluate dice rolling notation strings

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Rules Write a function that accepts string as a parameter, returning evaluated value of expression in dice notation , including addition and multiplication. To clear the things up, here comes EBNF definition of legal expressions: roll ::= [positive integer], "d", positive integer entity ::= roll | positive number expression ::= entity { [, whitespace], "+"|"*"[, whitespace], entity } Example inputs: "3d6 + 12" "4*d12 + 3" "d100" Using eval functions, or similar, is not forbidden, but I encourage to solving without using these. Re-entrancy is

How to let the user enter any amount of variable from Console

匿名 (未验证) 提交于 2019-12-03 02:42:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This is the code that I have made that rolls two dice until a pair appear. My question is, is there a way for the user to enter any amount of dice he/she wants? I don't want to create 50 int dice. If I use an array or List I would have the same problem. I'd have to assign each array section to numbergen 50 or more times. Maybe there is something I am missing? static void Main(string[] args) { Random numbergen = new Random(); int dice1=0; int dice2=1; for (int counter = 0; counter <= 1; counter++) { while (dice1 != dice2) { dice1 = numbergen

Typeerror: object.__new__() takes no parameters (help)

匿名 (未验证) 提交于 2019-12-03 02:26:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm simply trying to make a code that generates dice (in python). Here's the code: import random class Dice: def _init_(self, number_dice): self._dice = [6] * number_dice def roll_dice(self): for d in range(len(self._dice)): self._dice[d] = random.randit(1, 6) self._dice.sort() def print_roll(self): length = len(self._dice) print(str(lenth) + "dice:" + str(self._dice)) my_dice = Dice(2) my_dice.roll_dice() my_dice.print_roll() The compiler says something about line 18. I'm new to programming so anything helps =] 回答1: You need two underscores

Evaluate dice rolling notation strings

牧云@^-^@ 提交于 2019-12-03 02:02:14
问题 Rules Write a function that accepts string as a parameter, returning evaluated value of expression in dice notation, including addition and multiplication. To clear the things up, here comes EBNF definition of legal expressions: roll ::= [positive integer], "d", positive integer entity ::= roll | positive number expression ::= entity { [, whitespace], "+"|"*"[, whitespace], entity } Example inputs: "3d6 + 12" "4*d12 + 3" "d100" Using eval functions, or similar, is not forbidden, but I

Evaluate dice rolling notation strings

坚强是说给别人听的谎言 提交于 2019-12-02 15:38:31
Rules Write a function that accepts string as a parameter, returning evaluated value of expression in dice notation , including addition and multiplication. To clear the things up, here comes EBNF definition of legal expressions: roll ::= [positive integer], "d", positive integer entity ::= roll | positive number expression ::= entity { [, whitespace], "+"|"*"[, whitespace], entity } Example inputs: "3d6 + 12" "4*d12 + 3" "d100" Using eval functions, or similar, is not forbidden, but I encourage to solving without using these. Re-entrancy is welcome. I cannot provide test-cases, as output