码迷,mamicode.com
首页 > 其他好文 > 详细

Exercise 38 - list

时间:2019-09-30 21:53:20      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:range   day   ext   ali   hone   out   int   output   size   

 

ten_things = "Apples Oranges Crows Telephone Light Sugar"

print("Wait there‘s not 10 things in that list, let‘s fix that.")

stuff = ten_things.split( )
more_stuff = ["Day", "Night", "Song", "Frisbee", "Corn", "Banana", "Girl", "Boy"]

while len(stuff) != 10:
    next_one = more_stuff.pop()
    print("Adding: ", next_one)
    stuff.append(next_one)
    print("There‘s %d items now." % len(stuff))
    
print("There we go:", stuff)

print("Let‘s do some things with stuff.")

print(stuff[1])
print(stuff[-1]) # whoa! fancy
print(stuff.pop())
print( .join(stuff)) # what? cool!
print(#.join(stuff[3:5])) # super stellar!

output

Wait theres not 10 things in that list, lets fix that.
Adding:  Boy
Theres 7 items now.
Adding:  Girl
Theres 8 items now.
Adding:  Banana
Theres 9 items now.
Adding:  Corn
Theres 10 items now.
There we go: [Apples, Oranges, Crows, Telephone, Light, Sugar, Boy, Girl, Banana, Corn]
Lets do some things with stuff.
Oranges
Corn
Corn
Apples Oranges Crows Telephone Light Sugar Boy Girl Banana
Telephone#Light

 

2019-10-01

01:22:22

Exercise 38 - list

标签:range   day   ext   ali   hone   out   int   output   size   

原文地址:https://www.cnblogs.com/petitherisson/p/11614083.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!