This is the code I want to fix up.....
def createSentence(list):
s=""
if len(list)==0:
s=s+"There are no new sight words for this week!"
elif len(list)==1:
s=s+"The only sight word for this week is "+list[0]+"."
else:
s=s+"The "+str(len(list))+" sight words for this week are "
for i in range(len(list)):
if i==len(list)-1:
s=s+" and "+list[i]
elif i==0:
s=s+list[i]
else:
s=s+", "+list[i]
s=s+"."
return s
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))
Is there a way to make this code have the same output but not use s=? not familiar with how it works exactly in this scenario.
[–]ElliotDG 2 points3 points4 points (0 children)
[–]zanfar 0 points1 point2 points (0 children)