问题描述
在这种共享算法中,探矿者轮流获取金块。编写一个名为turns(n)的函数来计算每个探测器获得的金量,并在Turtle Graphics中显示。你的函数应该看起来像这个伪代码版本。该函数应该有一个参数,即探矿者之间共享的金块数量。我希望你会想要编写轮流调用的其他函数(移动乌龟,绘制正方形等)。
将p1'的黄金设为0
将p2'的黄金设为0
给定数量的金块
将金块设置为10到100之间的随机数(其值)
如果是prospetor1轮到
将金块添加到p1
显示prospector1'的金块
else
将金块添加到p2
显示prospector2'的金块
这是我的所得,但我不知道如何轮流并显示每个玩家的结果
In this sharing algorithm the prospectors take it in turns to get gold nuggets. Write a function called turns(n) to calculate the amount of gold that each prospector gets, and to display this in Turtle Graphics. Your function should look something like this pseudocode version. The function should have a single parameter, the number of gold nuggets to be shared between the prospectors. I expect that you will want to write other functions that are called by turns (to move the turtle, draw squares and so on).
set p1''s gold to 0
set p2''s gold to 0
for a given number of nuggets
set nugget to a random number between 10 and 100 (its value)
if it is prospetor1''s turn
add nugget to p1
display prospector1''s nugget
else
add nugget to p2
display prospector2''s nugget
Here is what i have got, but i do not know how to take turns and show the result of each player
这篇关于需要python的帮助,简单(关于轮流)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!