I need to create a function that returns a string value and then I print the value by passing a list to the function and then calling the function. The output would look like below :
The 7 sight words for this week are new, barn, shark, hold, art, only and eyes.
The 2 sight words for this week are subtract and add
The 9 sight words for this week are girl, house, best, thing, easy, wrong, right, again, and above.
The only site word for this week is question
There are no new sight words for this week!
My current code give's me the variables (except for str1) but only passes 1 value of the list. I can accomplish this using Join but the instructor specifically said not to use Join. However, even with Join I was struggling with how to get the 'and' value in the proper location. Any guidance would be appreciated!
Current Code :
def createSentence(list):
list1 = list
str1 = 'There are no new sight words for this week!'
str2 = 'The only site word for this week is '
str3 = 'The ' + str(len(list)) + ' sight words for this week are '
for list1 in list:
if len(list) == 0:
return str1
elif len(list) == 1:
return(str2 + list1)
elif len(list) > 1:
return(str3 + list1 + ',')
week1 = ['new', 'barn', 'shark', 'hold', 'art', 'only', 'eyes']
week2 = ['subtract', 'add']
week3 = ['girl', 'house', 'best', 'thing', 'easy', 'wrong', 'right', 'again', 'above']
week4 = ['question']
week5 = []
print(createSentence(week1))
print(createSentence(week2))
print(createSentence(week3))
print(createSentence(week4))
print(createSentence(week5))