It doesn't work because you have the for words in splitted loop inside your loop with the lineLen condition. You have to do this:
if len(inputStr) > 40:
print "The short description is longer than 40 characters"
else:
for word in splitted:
if lineNum > 5:
break
if word != None:
if len(lineNumDict[lineNum]+word) <= lineLengths[lineNum]:
lineNumDict[lineNum] += word
else:
lineNum += 1
else:
if len(lineNumDict[lineNum])+1 <= lineLengths[lineNum]:
lineNumDict[lineNum] += " "
else:
lineNum += 1
Also lineStr1, lineStr2 and so on won't be changed, you have to access the dict directly (strings are immutable). I tried it and got the results working:
print("Lines: %s" % lineNumDict)
Gives:
Lines: {1: 'THIS IS A', 2: 'LONG DESC 7', 3: '7 NEEDS ', 4: '', 5: ''}