凌北辰 2020-11-17 08:52 采纳率: 66.7%
浏览 18
已结题

谁能帮我注释下代码呀

import pygame, sys  # 导入游戏模块


# 通过range()函数生成列表[1,2,3,4,5]
# print(list(range(0,10)))
# for循环
# for i in range(0,10):
#    print(i)
# 列表添加元素
# mylist = [1,2,3,4]
# mylist.append(5)
# print(mylist)

def lineleft():#定义函数lineleft()
    plotponits = []
    for x in range(0, 640):
        y = 1000-5*x
        plotponits.append([x, y])
    pygame.draw.lines(screen, [44, 100, 200], False,plotponits,5)
    pygame.display.flip()
def lineright():
    plotponits = []
    for x in range(0,640):
        y=5*x-2000
        plotponits.append([x, y])

    pygame.draw.lines(screen,[44,100,200],False,plotponits,5)
    pygame.display.flip()

def linemiddle():
    x = 300
    plotponits = []
    for y in range(0,480,20):
        plotponits.append([x,y])
        if len(plotponits)==2:
            pygame.draw.lines(screen,[200,10,30],False,plotponits,5)
            plotponits = []

    pygame.display.flip()
pygame.init()#
screen = pygame.display.set_caption("马路牙子")
screen = pygame.display.set_mode([640, 480])

screen.fill([255, 255, 255])

lineleft()#调用函数lineleft
lineright()
linemiddle()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
  • 写回答

2条回答 默认 最新

  • 煜眠 2020-11-17 16:54
    关注
    作者:知乎用户
    链接:https://www.zhihu.com/question/20388430/answer/112665252
    来源:知乎
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
    
    #!/usr/bin/python
    #coding=gbk
    # Filename: if.py
    
    #----->1.用一对"""括起来要注释的代码:
    """
      number = 23
      guess = int(raw_input('Enter an integer : '))
      if guess == number:
      print 'Congratulations, you guessed it.' # New blockstarts here
      print "(but you do not win any prizes!)" # New blockends here
      elif guess < number:
    """
    #----->2.用一对'''括起来要注释的代码块:
    '''
      print 'No, it is a little higher than that' #Another block
    # You can do whatever you want in a block ...
    else:
    '''
    #----->3.选中要注释的代码,按下ctrl+/注释:
    #   print 'No, it is a little lower than that'
    # # you must have guess > number to reach here
    # print 'Done'
    # # This last statement is always executed, after the ifstatement is executed

    我用的pycharm有这三种方法可以注释代码的

    评论

报告相同问题?