第一句子网 - 唯美句子、句子迷、好句子大全
第一句子网 > 笨办法学python3_笨办法学python3—练习38

笨办法学python3_笨办法学python3—练习38

时间:2022-07-16 14:36:23

相关推荐

笨办法学python3_笨办法学python3—练习38

这个习题还是做得蛮顺的,唯一的疑问是在定义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=Truefor 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 = Trueelse:things=Falseprint('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]))

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。