• 8回复贴,共1
画立方体
import turtle #导入绘图
turtle.goto(200,0) #到坐标200,0
turtle.goto(200,200)
turtle.goto(0,200)
turtle.goto(0,0)
turtle.pendown() #放下画笔
turtle.penup() #拾起画笔
turtle.goto(100,100) #跳到坐标 100,100
turtle.pendown()
turtle.goto(100,-100)
turtle.goto(-100,-100)
turtle.goto(-100,100)
turtle.goto(100,100)
turtle.pendown()
turtle.goto(200,200) #连接坐标(100,100)和(200,200)
turtle.pendown()
turtle.penup()
turtle.goto(100,-100) #到坐标(100,-100)
turtle.pendown()
turtle.goto(200,0) #连接(100,-100)和(200,0)
turtle.pendown()
turtle.penup()
turtle.goto(-100,-100)
turtle.pendown()
turtle.goto(0,0)
turtle.pendown()
turtle.penup()
turtle.goto(-100,100)
turtle.pendown()
turtle.goto(0,200)
turtle.done() #显示出来


1楼2018-03-26 13:26回复
    画五角星
    import turtle
    turtle.forward(100) #turtle.forward()向前移动
    turtle.right(144) #右转144度
    turtle.forward(100) #turtle.forward()向前移动
    turtle.right(144)
    turtle.forward(100) #turtle.forward()向前移动
    turtle.right(144)
    turtle.forward(100) #turtle.forward()向前移动
    turtle.right(144)
    turtle.forward(100) #turtle.forward()向前移动
    turtle.right(144)


    2楼2018-03-26 13:36
    回复
      2026-04-28 17:29:41
      广告
      不感兴趣
      开通SVIP免广告
      已知坐标求长度
      import turtle
      x1,y1=eval(input("输入两个点坐标")) #输入的时候用,分隔,连续输入三个数
      print(x1,y1)
      x2,y2=eval(input("输入两个点坐标")) #输入的时候用,分隔,连续输入三个数
      print(x2,y2)
      turtle.penup()
      turtle.goto(x1,y1)
      turtle.write(str(x1)+","+str(y1)) #写下(x1,y1)的坐标
      turtle.pendown()
      turtle.goto(x2,y2)
      turtle.write(str(x2)+","+str(y2))
      turtle.goto((x1+x2)/2,(y1+y2)/2)
      turtle.write(((x2-x1)**2+(y2-y1)**2)**0.5) #写下长度
      turtle.done()


      3楼2018-03-26 15:04
      回复
        数学公式应用
        import math #导入数学包
        print(abs(-5)) #abs求绝对值
        print(max(1,2,3,10,111))#max返回最大值
        print(pow(2,4))#pow(x,y),x**y
        print(math.sqrt(9)) # math.sqrt(x),x**0.5


        4楼2018-03-26 15:15
        回复
          查找函数
          import math
          print(dir(math)) #显示所有函数
          print(help(math.atan)) #显示函数说明


          5楼2018-03-26 15:19
          回复
            #ASCII
            ch1='A'
            ch2='AB'
            print(type(ch1)) #pyth只有字符串类型
            print(type(ch2))
            print(ord(ch1)) #ord求字符编号
            print(chr(97)) #求编号为97的字符


            6楼2018-03-26 15:31
            回复
              ch='A'
              print(chr((ord(ch)+1))) #用于加密


              7楼2018-03-26 15:44
              回复
                print(chr(25105))
                print("\u6211") #\u表示统一码,6211是25105的16进制


                8楼2018-03-26 15:47
                回复
                  2026-04-28 17:23:41
                  广告
                  不感兴趣
                  开通SVIP免广告
                  #转义字符
                  import os
                  os.system("D:\Bin\QQScLauncher.exe") #D:\Bin\QQScLauncher.exe是QQ的位置,打开QQ
                  print("he\nllo\"\'")# \"在双引号内输入双引号,\n换行


                  9楼2018-03-26 15:54
                  回复