《python编程从入门到精通》

message="你好"
print(message)

messages = "你好,\n最近还好吗"
print(messages)

m= 4 + 4
print(m)
n= 4*2
print(n)
s= 10-2
print(s)
u= 16/2
print(u)
message = "我最喜欢的数字是"+str(m)
print(message)

name = "ada love"
print (name.title())
print (name.upper())
print(name.lower())

#鲍勃想说的话 练习注释
Bob = "Hello Eric,would you like to learn some ptython today?"
print(Bob)

name = "wu qi"
print(name.title())
print(name.lower())
print(name.upper())

famous = "鲁迅曾经说过,“这世界上本没有路,走的人多了,便有了路。”这句话非常有名。"
print(famous)

famous_person = "鲁迅:"
message = "这世界上本没有路,走的人多了,便有了路。"
print(famous_person)
print(message)

name = "\t鲁迅\n "
print(name)
r_nane = name.rstrip()
l_name = name.lstrip()
s_name = name.strip()
print(r_nane)
print(l_name)
print(s_name)

fruits =["apple","banana","pear"]
print(fruits[0])
print(fruits[0].title())
print(fruits[1])
print(fruits[2])
print(fruits[-1])
print(fruits[-2])
print(fruits[-3])
message = f"我最喜欢吃{fruits[1].title()}"
print(message)

十一

frirnds = ["小红","小绿","小兰","小四"]
print(frirnds[0])
print(frirnds[1])
print(frirnds[2])
print(frirnds[3])
print(f"{frirnds[0]},你好!")
print(f"{frirnds[1]},你好!")
print(f"{frirnds[2]},你好!")
print(f"{frirnds[3]},你好!")
frirnds[0] = '小黄'
print(frirnds)
frirnds.append('小明')
print(frirnds)
frirnds.insert(0,'李华')
print(frirnds)
del frirnds[1]
print(frirnds)

十二

#列表内删除某个元素,还要用,就用pop,不用了就用del
friends = ["小红","小绿","小兰","小四"]
print(friends)
popped_friend =friends.pop()
print(friends)
print(popped_friend)
del friends[1]
print(friends)

goods =['衣服','鞋子','饮料','面包','酒']
last_bought = goods.pop()
print(f"最新购买的是{last_bought}")

十三

friends = ["小红","小绿","小兰","小四"]
print(friends)
friends.remove("小四")
print(friends)
goods =['衣服','鞋子','饮料','面包','酒']
no_money = '鞋子'
goods.remove(no_money)
print(goods)
print(f"因为{no_money}太贵了,没钱,买不起。")

十四

people =['dog','cat','lion','elephant','rat']
print(people)
print(f"I'm glad to see you,{people[0]}")
print(f"I'm glad to see you,{people[1]}")
print(f"I'm glad to see you,{people[2]}")
print(f"I'm glad to see you,{people[3]}")
print(f"I'm glad to see you,{people[4]}")
people[1] = 'rabbit'
print(people)
no_time = 'cat'
print(f"{no_time.title()} said he need to go home to play with his children.")
print(f"I'm glad to see you,{people[0]}")
print(f"I'm glad to see you,{people[1]}")
print(f"I'm glad to see you,{people[2]}")
print(f"I'm glad to see you,{people[3]}")
print(f"I'm glad to see you,{people[4]}")
print(f"I find a bigger table to make a meal")
people.insert(0,'bear')
people.insert(2,'monkey')
people.append('pig')
print(people)
print(f"I'm glad to see you,{people[0]}")
print(f"I'm glad to see you,{people[1]}")
print(f"I'm glad to see you,{people[2]}")
print(f"I'm glad to see you,{people[3]}")
print(f"I'm glad to see you,{people[4]}")
print(f"I'm glad to see you,{people[5]}")
print(f"I'm glad to see you,{people[6]}")
print(f"I'm glad to see you,{people[7]}")
print(f"Only two person I can invite.")
no_1 = people.pop(0)
print(f"I'm so sorry that I can not invite to you,{no_1}")
no_2 = people.pop(0)
print(f"I'm so sorry that I can not invite to you,{no_2}")
no_3 = people.pop(0)
print(f"I'm so sorry that I can not invite to you,{no_3}")
no_4 = people.pop(0)
print(f"I'm so sorry that I can not invite to you,{no_4}")
no_5 = people.pop(0)
print(f"I'm so sorry that I can not invite to you,{no_5}")
no_6 = people.pop(0)
print(f"I'm so sorry that I can not invite to you,{no_6}")
print(f"I'm so happy to have a date to you,{people[0]}.")
print(f"I'm so happy to have a date to you,{people[1]}.")
del people[0]
print(people)
del people[0]
print(people)

十五

colors = ['red', 'green','blue','white']
#colors.sort(reverse=True)
colors.sort()
print(colors)

十六

colors = ['red', 'green','blue','white']
print("Here is a original list:")
print(colors)
print("\nHere is a original list:")
print(sorted(colors))
print("\nHere is a original list again:")
print(colors)
colors.reverse()
print(colors)
print(len(colors))

十七

address = ['yunnan','qindao','beijing','hangzhou']
print(address)
print(sorted(address))
print(address)
address.reverse()
print(address)
address.reverse()
print(address)
address.sort()
print(address)
address.sort(reverse= True)
print(address)

十八

excellents = ['weihe','yuxin','kazike','pulao','nimbus']
for excellent in excellents:#冒号不要忘
    print(f"{excellent.title()},I respect you.")
    print(f"I hope {excellent.title()} can teach me , thannk,you!")
print(f"You are so excellent.")

十九

foods =['noodles','bread','rice']
for food in foods:
    print(f"I like {food}.")
print(f"In terms of foods,I always eat different foods in the morning,\
so I like noodles , bread, rice and so on.I really love foods!")

二十

for value in range(1,8):
    print(value)
for value in range(8):
    print(value)
numbers = list(range(1,8))
print(numbers)
even_numbers = list(range(2,13,2))#偶数打印
print(even_numbers)

二十一

forms = []
for value in range (1,11):
    form = value ** 2
    forms.append(form)
print(forms)
sums = sum(forms)
print(sums)

二十二

#列表解析
forms =[value ** 2 for value in range(1,11)]
print(forms)

二十三

shum = range(1,21)
for shu in shum:
    print(shu)
billions = range(1,1000001)
for billion in billions:
    print(billion)
print(min(billions))
print(max(billions))
print(sum(billions))

二十四

jishus = range(3,20,2)
for jishu in jishus:
    print(jishu)
threes = range(3,31,3)
for three in threes:
    print(three)
cubes =[]
for value in range(1,11):
    cube = value **3
    cubes.append(cube)
print(cubes)
cube_1 =[value ** 3 for value in range(1,11)]#没冒号
print(cube_1)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值