如何多次运行python程序

如何多次运行python程序,python,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.c

如何使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()

使用循环。此外,“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退出

for i in rangen:word_search我以前使用过它,但它不起作用。我需要程序重新开始并接受新的输入。我提供的代码可以做到这一点。你的问题是,你要求的是循环之外的输入,我在第2行和第3行修正了这个问题