Question

guys. I need to write a programme(function + main programme), which collects words, puts them into one list, then counts symbols in words and if has more symbols than number N, puts it into list2. Then I need to print out the second list. This is what I've got so far:


def WordsInLists(word, symbols, number):
    list1 = [word]
    list2 = [len.word > n]
    return(list2)

list1 = []
list2 = []
howmany = int(input("How many words will you write?"))
n = int(input("What will the n number be?"))
for i in range(0, howmany, 1):
        word = (input("Write the word "))
        list1 = list1 + [word]
        if len.word > n:
            list2 = list2 + [word]
        result = WordsInLists(list2) 
        print(result)

what should i do next or what should i change?

Was it helpful?

Solution

This code will do what you want:

list1 = []
list2 = []
howmany = int(input("How many words will you write?"))
n = int(input("What will the n number be?"))
for i in range(0, howmany, 1):
        word = raw_input("Write the word ")
        list1 = list1 + [word]
        if len(word) > n:
            list2 = list2 + [word]
print list2

OTHER TIPS

(This assumes Python 3.x):

def get_int(prompt):
    while True:
        try:
            return int(input(prompt))
        except ValueError:  # not an int
            pass

def main():
    wordlen = get_int("How many words to enter? ")

    words = input("Please enter the words, separated by spaces:\n").split()
    list1, list2 = words[:wordlen], words[wordlen:]

    print("Leftover words: {}".format(", ".join(list2)))

if __name__=="__main__":
    main()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top