last 1 我发4这是最后一次py入门&processing初

2018-12-26  本文已影响0人  反复练习的阿离很笨吧
def merge_sort(lst):
    if len(lst)<=1:
        return lst
    middle=int(len(lst)/2)
    left=merge_sort(lst[:middle])
    right=merge_sort(lst[middle:])
    merged=[]
    while left and right:
        merged.append(left.pop(0) if left[0]<=right[0] else right.pop(0))
    merged.extend(right if right else left)
    return merged

data_lst=[6,202,100,301,38,8,1]
print(merge_sort(data_lst))
import datetime
dtstr="20181206"
dt=datetime.datetime.strptime(dtstr,"%Y%m%d")
another_dtstr=dtstr[:4]+'0101'
another_dt=datetime.datetime.strptime(another_dtstr,"%Y%m%d")
print(int((dt-another_dt).days)+1
import string

s='ww-m/23 4j)'
letter=0
space=0
digit=0
other=0
for c in s:
    if c.isalpha():
        letter+=1
    elif c.isspace():
        space+=1
    elif c.isdigit():
        digit+=1
    else:
        other+=1
print('There are %d letters,%d spaces,%d digits and %d others.'%(letter,space,digit,other))
triange=[1]
print(triange)
triange.append(0)
n=10
for i in range(1,n):
    newline=[]
    for j in range(i+1):
        value=triange[j]+triange[-j-1]
        newline.append(value)
    print(newline)
    triange=newline
    triange.append(0)
运算符

复习了去年暑假看的python课,大致过了一下,在输入上面,还是有些卡壳。
才知道py3把raw_input给去掉了。
好久没做题,格式化输出也忘记了,下面是我的智障敲打。


我zz吗

void setup(){
//初始化定义
size(500,500);//定义
background(214);//black:0 white:255
//ctrl+r:run
}

void draw(){
//background(255);
ellipse(250,250,100,100);//右键:在文档中搜索,有help
//processing的坐标轴体系:以左上角为(0,0)点
ellipse(mouseX,mouseY,100,100);
//有拖影是因为背景没有刷新,如果在draw里加上background(255),就不会有拖影了~
}

void draw(){
background(255);
//以中心点rectMode(CENTER);
stroke(255,255,0);//对线条的颜色的改变
fill();//对对象填色
rect(width/2,height/2,400,400);
ellipse(width/2,height/2,100,100);//width和height分别表示画布的宽和高
point(width/2,height/2)
//ctrl+t:规整代码
}

void setup() {
  size(500, 500);//the size if
  background(214);//black:0 white:255
  //ctrl+r:run
}

void draw() {
  background(#B0DE00);
  rectMode(CENTER);
  stroke(#D13602);
  fill(#D13602);
  rect(width/2, height/2, 200, 200);
  
  fill(#02D1BE);
  rect(width/2, height/2, 300, 300,40,40,40,40);
  ellipse(mouseX, mouseY, 100, 100);
  
  strokeWeight(10);
  point(width/2, height/2);
  line(width/2, height/2, width/2, 500);
}
上一篇下一篇

猜你喜欢

热点阅读