php 如何解决这个程序

cwdobuhd  于 2022-11-21  发布在  PHP
关注(0)|答案(1)|浏览(184)

剩余斗杆数= 13 *“|“sticks = 13次打印(f '{sticks_remaining} {sticks}剩余sticks')
player = 1 print(“您可以拾取1到4根”)pickup = input(“您要拾取多少根?:\n”)
sticks_remaining1 = sticks_remaining -捡拾sticks = sticks -捡拾打印(f '{sticks_remaining1} {sticks} sticks remaining')

yjghlzjz

yjghlzjz1#

我认为我们可以将sticks字符串推到array中,并根据输入选择删除元素。

def joinString(array):
    return ' '.join([str(elem) for elem in array])

sticks = list(13 * "|")
sticks_remaining = joinString(sticks)
print(f' {sticks_remaining} sticks remaining')

player = print("You may pickup between 1 to 4")
pickup = input("How many sticks do you want to pickup?:\n")

del sticks[0:int(pickup)]
remSticks = joinString(sticks)
print(f'{remSticks} sticks remaining')

相关问题