I’ve been given a small task – to get the user to input a limerick, and for the program to store each line in a list as the line is entered. (I then have to print the limerick back)
This is my current code:
limerick_line = []
for i in range(5):
limerick_line[i].append = input("Type in a limerick line. ")
print(limerick_line[5])
I know I’m doing quite a lot wrong, but I’m not exactly sure how to get it right. The current error is “list index out of range”.
You just need to use
limerick_line.append(input('enter line: '))– no need to try and index it… And your finalprintcan be justprint(limerick_line)or loop over it:So, corrected code is: