python骰子滚动重启脚本
我想自动重新启动我的脚本我有一个掷骰子脚本,我不想在每次掷骰之间手动重置脚本这是我的脚本python骰子滚动重启脚本,python,Python,我想自动重新启动我的脚本我有一个掷骰子脚本,我不想在每次掷骰之间手动重置脚本这是我的脚本 import random from random import randrange from random import randint r = randint min = 1 max = 6 rolls = int(float(input('how menny times do you want to roll:'))) for x in range(rolls): print ('Roll
import random
from random import randrange
from random import randint
r = randint
min = 1
max = 6
rolls = int(float(input('how menny times do you want to roll:')))
for x in range(rolls):
print ('Rolling the dices...')
print ('The value is....')
print (r(min, max))
我尝试过几种方法,但没有一种有效我不能100%确定您实际上想做什么,但我编写了一个程序,它将一次滚动2次,并将生成您想要滚动的滚动数量-使用递归(main从自身内部调用main)并不是最佳实践,但这并不是一个基本问题 *如果您使用的是Python 3+,请将原始输入替换为输入。我使用2.7,所以我使用原始输入
import time
import random
def roll_multiple():
#honestly this is all you need to do what you want to do, the rest just turns it into a game and allows multiple runs
roll_number = int(raw_input("How Many Times Would You Like to Roll?\n"))
for i in range(roll_number):
print"You Rolled A ", random.randrange(1,6,1), " and a ", random.randrange(1,6,1)
#that's it! if you do these 3 lines, it will ask for how many times, and for each item in range of roll_number (whatever you input) it will run the print below and generate new numbers for each roll.
def main():
print("Welcome to Craps 2.0")
playing = raw_input("Press Enter to Roll or Q to quit")
if playing == 'q':
print("Thanks for Playing")
time.sleep(2)
quit()
elif playing != 'q':
roll_multiple()
main()
main()
你尝试过哪些方法,哪些方法不奏效?仅供参考,
'menny'!='许多“
。听起来你应该阅读while循环
一个简单的while循环
就可以了。谢谢我编辑了这个,使之与我的python版本一起使用,它工作得非常好。