问题是:
我们必须创建一个游戏,用户输入他们想要使用的铅笔数量.
How many pencils would you like to use:
> 5
Who will be the first (John, Jack):
> John
|||||
John's turn:
> 2
|||
Jack's turn:
> 1
||
John's turn:
> 2
My solution:
person = input("Who will be the first (John, Jack):")
print("|" * number_of_pencil)
print(f"{person}'s turn")
while number_of_pencil > 1:
pencil = int(input())
number_of_pencil -= pencil
print("|" * number_of_pencil)
if person == "John":
print("Jack's turn")
person = "Jack"
else:
print("John's turn")
person = "John"
The output:
Who will be the first (John, Jack):> John
|||||
John's turn
> 2
|||
Jack's turn
> 1
||
John's turn
> 2
Jack's turn
Suggestion required:我该如何打破循环?