这个习题还是做得蛮顺的,唯一的疑问是在定义nextone变量时,pop从more_stuff里面取值时,取的却是从后面往前取的。不明觉厉~~
下面是用for循环改写的程序,竟然写出来了,有点小小的兴奋和成就感:)
ten_things='apple orange crows telephone light sugar'
print('wait, there are not 10 things in that list. lets fix it')
stuff=ten_things.split(' ')
more_stuff=['day','night','song','frisbee','corn','banana','girl','boy']
things=True
for items in stuff:
if len(stuff)<=9 and things:
next_one=more_stuff.pop()
print('adding: ', next_one)
stuff.append(next_one)
print(f"there'are {len(stuff)} items now")
things = True
else:
things=False
print('there we go: ', stuff)
print("let's do some things with stuff.")
print(stuff[1])
print(stuff[-1])
print(stuff.pop())
print(' '.join(stuff))
print('#'.join(stuff[3:5]))