Python中文
首页
教程
问答
标签
搜索
登录
注册
我试图使我的骰子游戏,使它不是改变一个数字的骰子每卷它改变所有的
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>所以问题在第9行到第32行,它的输出是“3 0 0”,然后是“3 4 0”,然后是“3 4 6”。相反,它应该说“3 4 6”,然后它可以是“6 1 2”。我知道这和numRolled变量以及它循环的方式有关,但我想不出还能把它放在哪里</p> <p>我试着把numRolled=0放在“for I in range(3)”的末尾,但这样做只是为了只改变第一个数字。我试着把这些数字做成一个单变量列表,但是我对列表中的编码没有信心,所以我决定用这里的代码</p> <pre><code>def DiceGame(): numRolled = 1 RunScore = 0 Roll1 = 0 Roll2 = 0 Roll3 = 0 #rolls the 3 dice 100 times for x in range(100): numRolled = 0 #rolls the 3 dice for i in range(3): score = rdm.randint(1,6) numRolled += 1 #assigns score to each die if numRolled == 1: Roll1 = score if numRolled == 2: Roll2 = score if numRolled == 3: Roll3 = score if Roll1 == Roll2 and Roll1 == Roll3: RunScore += 100 else: DiceTot = Roll1 + Roll2 + Roll3 # If Total of Die MOD 2 == 0 then Running score += Dice Total if DiceTot % 2 == 0: RunScore += DiceTot else: RunScore -= DiceTot print(Roll1, Roll2, Roll3) print(RunScore) </code></pre> <p>正如我上面所说,它的输出是“3 0 0”然后是“3 4 0”然后是“3 4 6”。相反,它应该说“3 4 6”,然后它可以是“6 1 2”</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>改变这个</p> <pre><code>def game: forlopp: forloop: print() print() </code></pre> <p>为了这个</p> <pre><code>def game: forlopp: forloop: print() print() </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在python中从数据帧列中删除分类值?
3 回答
如何在python中从数据帧列表中删除引号
10 回答
如何在python中从数据帧创建列表
6 回答
如何在Python中从数据帧创建嵌套的JSON
1 回答
如何在Python中从数据帧显示wordcloud
3 回答
如何在Python中从数据帧的时间戳中删除字符
5 回答
如何在Python中从数据帧绘制简单绘图?
4 回答
如何在python中从数据帧行提取具有特定长度的范围?
2 回答
如何在python中从数据帧设置dict中的值
3 回答
如何在Python中从数据库中获得一个结果
7 回答
如何在python中从数据框中绘制分类条形图
8 回答
如何在Python中从数据框中选择特定细节?
8 回答
如何在python中从数据集中删除unicode
6 回答
如何在python中从数据集中删除某些数值?
6 回答
如何在python中从数据集中选择行
5 回答
如何在Python中从数组中删除元素
7 回答
如何在python中从数组中删除单个倒逗号?
3 回答
如何在python中从数组中删除对象?
10 回答
如何在python中从数组中删除引号
5 回答
如何在python中从数组中删除所有最小值
2 回答