如何不止一次运行python程序

时间:2014-10-20 22:13:48

标签: python

如何让我的python程序运行多次而不必重新启动它。 以下是代码:

words = [str(x) for x in raw_input().split(' ')]

string = raw_input()

def word_search():

    for x in words:

        while len(string)==30:
            if x in string:
                print x, 'appeared', string.count(x), 'time(s)'
            else:
                print x, 'appeared', string.count(x), 'time(s)'

            break

        else:
            print 'Your longer string should not be less or more than 30.'
word_search()

1 个答案:

答案 0 :(得分:0)

使用循环。另外,' string'不是一个好的变量名。

def word_search():
    words = [str(x) for x in raw_input().split(' ')]
    string = raw_input()
    for x in words:

        while len(string)==30:
            if x in string:
                print x, 'appeared', string.count(x), 'time(s)'
            else:
                print x, 'appeared', string.count(x), 'time(s)'

            break

        else:
            print 'Your longer string should not be less or more than 30.'
While True:    
    word_search()

您可以在主循环中使用break退出

相关问题