1. 首页 > 科技

用python回答sos?

用python回答sos?

新手请教Python的字符串问题:给定一个字符串s,要求统计s中'sos'字符串出现的次数?

直接贴代码,思路就是遍历字符串,截取字符串的当前位置到末尾,然后搜索要搜索的字符串是否在第一个位置,若是,则+1.表达的不太清楚,看程序吧!

def search(s1,s2):

    sum = 0

    for i in range(0,len(s1)):

        str = s1[i:]

        if(str.find(s2) == 0):

            sum += 1

        else:

            continue

    return sum

def main():

    s1 = 'asdlbsosososkqio'

    s2 = 'sos'

    print(search(s1,s2))

if __name__ == '__main__':

    main()

使用Python进行验证码识别案例无法验证通过,SOS

Unsupported image object 估计是你的png内容不规范。。。

先规范下格式再用吧。

Image.open(r'F://work//test//python//222.png').save("222.png")

img = Image.open("222.png")

vcode = pytesseract.image_to_string(img)

求一个python的小程序,最好能用上graphics库,并且有意思一点的,不要很长,几十行即可。SOS!!!

# draw a circle on top of two rectangles

# using module graphics from:

# mcsp.wartburg.edu/zelle/python/graphics.py

from graphics import *

# create the window/frame

w = 300

h = 300

win = GraphWin("Red Circle", w, h)

# first rectangle using corner x, y coordinates

upper_left = Point(0, 0)

lower_right = Point(300, 150)

rect1 = Rectangle(upper_left, lower_right)

rect1.setFill('yellow')

rect1.setWidth(0) # no border

rect1.draw(win)

# second rectangle using corner x, y coordinates

upper_left = Point(0, 150)

lower_right = Point(300, 300)

rect2 = Rectangle(upper_left, lower_right)

rect2.setFill('green')

rect2.setWidth(0) # no border

rect2.draw(win)

# circle needs center x, y coordinates and radius

center = Point(150, 150)

radius = 80

circle = Circle(center, radius)

circle.setFill('red')

circle.setWidth(2)

circle.draw(win)

# wait, click mouse to go on/exit

win.getMouse()

win.close()

[SOS]请问怎样使用GUI?

是的,是写好了一个py文件,然后在交互环境里import的,Label类可以用EntryDemo().mainloop()调用,虽然用main()不行,而后面的Entry,  2种方法都不行了,不知道哪出错了,帮忙看看好吗?谢谢,代码在上面[ 本帖最后由 jubao1hao 于 2006-7-22 21:24 编辑 ]