当乌龟到达class block_ivas_block_renderer extends plugin_renderer_base {
public function get_mcontent($text) {
$content = html_writer::start_tag('div', array('class'=>'mstyle'));
$content .= '<div>';
$content .= html_writer::empty_tag('input', array('id' => 'inputtext', 'type' => 'text', 'name' => 'input'));
$content .= html_writer:: tag('button','Submit', array('id' => 'button', 'type' => 'submit'));
$content .= '</div>';
$content .= html_writer:: tag('label',$text,array('class'=>'mstyle'));
$content .= html_writer::end_tag('div');
return $content;
}
}
时,我不知道如何打破python while循环
t.ycor == 0
我想在完成import turtle
import msvcrt
turtle.setup(700, 300, 0, 0)
t=turtle.Turtle()
t.up()
t.goto(-300,0)
t.down()
t.write("Start\n(" + str(t.xcor()) + ", " + str(t.ycor()) + ")", False, "center", ("",15))
while True:
if msvcrt.kbhit():
c = msvcrt.getch().decode(encoding = 'UTF-8')
if c == 'j':
t.left(3)
elif c == 'k':
t.right(3)
elif c == 'g':
t.forward(5)
t.right(3)
while t.ycor() > 0:
t.forward(10)
t.right(3)
t.write("End\n(" + str(t.xcor()) + ", " + str(t.ycor()) + ")", False, "center", ("",15))
print("When angle is", str(t.heading()), ", difference of x position is ", str(t.xcor()+300))
input("Press ENTER key to end")
之后跳出while True:
,
但我不知道如何...
答案 0 :(得分:1)
正在搜索的声音:
while True:
if msvcrt.kbhit():
c = msvcrt.getch().decode(encoding = 'UTF-8')
if c == 'j':
t.left(3)
elif c == 'k':
t.right(3)
elif c == 'g':
t.forward(5)
t.right(3)
while t.ycor() > 0:
t.forward(10)
t.right(3)
break
如果是这样,一个更好的解决方案是消除“ while True:”,因为该break循环只使用一次while循环-因此while不必要。