英文:
If last item printed on screen by a list in python turtle = value1 then move to a different position and print value 2
问题
my_values = ['value1', 'value2', 'value3']  # 这些值是字符串
def heading():
  if my_values == 'value1':
    setheading(90)
    forward(10)
  if my_values == 'value2':
    setheading(0)
    forward(30)
  if my_values == 'value3':
    setheading(270)
    forward(60)
def working_together():
 for loop in range(3):
    write(my_values[value_range], move = False, align = 'center')
    heading()
working_together()
英文:
Trying to see if its possible to do the following using python turtle graphics (assume modules have been imported already):
my_values = ['value1', 'value2', 'value3'] #these values are strings 
def heading():
  if my_values == 'value1':
    setheading(90)
    forward(10)
  if my_values == 'value2':
    setheading(0)
    forward(30)
  if my_values == 'value3':
    setheading(270)
    forward(60)
def working_together():
 for loop in range(3):
    write(my_values[value_range], move = False, align = 'center')
    heading()
working_together()
The main premise of what im trying to achieve is that if the item last printed on the screen by turtle == valueX then the turtle will then move to a different position. This must loop through until the loop is complete and all values have been printed?
Is this possible in python?
Ive tried the following:
def heading():
  if range(my_values == 'value1'):
    setheading(90)
    forward(10)
  if range(my_values == 'value2'):
    setheading(0)
    forward(30)
  if range(my_values == 'value3'):
    setheading(270)
    forward(60)
def heading():
  if range(len(my_values == 'value1')):
    setheading(90)
    forward(10)
  if range(len(my_values == 'value2')):
    setheading(0)
    forward(30)
  if range(len(my_values == 'value3')):
    setheading(270)
    forward(60)
答案1
得分: 1
将其作为参数传递给 heading()。
def heading(current_value):
  if current_value == 'value1':
    setheading(90)
    forward(10)
  elif current_value == 'value2':
    setheading(0)
    forward(30)
  elif current_value == 'value3':
    setheading(270)
    forward(60)
def working_together():
    for value in my_values:
        write(value, move=False, align='center')
        heading(value)
working_together()
英文:
Pass it as an argument to heading().
def heading(current_value):
  if current_value == 'value1':
    setheading(90)
    forward(10)
  elif current_value == 'value2':
    setheading(0)
    forward(30)
  elif current_value == 'value3':
    setheading(270)
    forward(60)
def working_together():
    for value in my_values:
        write(value, move = False, align = 'center')
        heading(value)
working_together()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论