import random
number_of_balls = int(input("Enter number of balls: "))
number_of_slots = int(input("Enter number of slots: "))
path = list ()
slots = list (range(0, number_of_slots))
direction = ["L", "R"]
i=0
def BallPath ():
balls = 0
while balls < number_of_balls:
balls += 1
order_of_path = random.randint(0, (len(direction) -1))
path.append(direction[order_of_path])
for x in path:
print (x, end=' ')
print("\n")
for i in range(0, number_of_slots):
BallPath()
这是我的密码
输出结果如下:
Enter number of balls: 2
Enter number of slots: 2
L L
L L L R
假设它在两行中做两个随机数,但是在第一行之后它从上一行加上。我该怎么修?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐