Python编程从入门到实践的第一天

# -*- coding = utf-8 -*-

#大家好,今天是2018年12月17日,天气还不错,我是皮卡丘,这是我看Python编程从入门到实践的第一天,现在是上午,我敲的是第二章的内容

print(‘hello world!’)

message = ‘hello python world!’

print(message)

message = ‘hello world!’

print(message)

name = ‘ada lovelace’

print(name.title())

print(name.upper())

print(name.lower())

first_name = ‘ada’

last_name = ‘lovelace’

full_name = first_name + ‘ ‘ +last_name

message = ‘Hello,’ + full_name.title() + ‘!’

print(message)

print(‘Hello ‘ + full_name.title() + ‘,Do you learn some Python today?’)

print(‘Languages:\n\tPython\n\tC\n\tJavaScript’)

favorite = ‘ python ‘

print(‘a’+favorite.strip()+’b’)

print(‘a’+favorite.rstrip()+’b’)

print(‘a’+favorite.lstrip()+’b’)

famous_person = ‘皮卡丘’

message = ‘时间就像海绵,挤挤总会有的!’

print(famous_person + ‘说过:’ + message)

name = ‘ Ada ‘

print(name.strip()+’\n’+name.lstrip()+’\t’+name.rstrip())

age=22

message = ‘Happy ‘+str(age)+’rd birthday!’

print(message)

print(5+3)

print(10-2)

print(2*4)

print(24/3)

number=6

message=’My favorite number is:’+str(number)

print(message)

#大家好,今天是2018年12月17日,天气还不错,我是皮卡丘,这是我看Python编程从入门到实践的第一天,现在是下午,我敲的是第三章的内容

bicycles = [‘trek’,’cannondale’,’redline’,’specialized’]

print(bicycles[0]+’\n’+bicycles[-1])

message = ‘My first bicycle was a ‘+bicycles[1].title()+’!’

print(message)

name = [‘zhang’,’li’,’wang’,’guo’,’liu’]

for temname in name:

message = ‘Hello,’+temname.title()+’,today is your first day that learned Python.’

print(message)

motrocycles = [‘honda’,’yamaha’,’suzuki’]

print(motrocycles)

motrocycles[0]=’ducati’

print(motrocycles)

motrocycles.append(‘honda’)

motrocycles.insert(2,’dayang’)

print(motrocycles)

del motrocycles[0]

print(motrocycles)

last_owned=motrocycles.pop()

print(‘The last motrocycle I owned was a ‘+last_owned.title()+’!’)

first_owned=motrocycles.pop(0)

print(‘The first motrocycle I owned was a ‘+first_owned.title()+’!’)

print(motrocycles)

too_expensive=’dayang’

motrocycles.remove(too_expensive)

print(motrocycles)

print(‘\nA ‘+too_expensive.title()+’ is too expensive for me.’)

#第三章的练习题1

invest_people = [‘pi’,’ka’,’qiu’,’xiao’,’hua’,’xue’]

for name in invest_people:

print(‘Hello,Mr ‘+name.title()+’ welcome to my party~’)

old=invest_people[3]

invest_people[3]=’ye’

print(‘因为一些原因,Mr ‘+old.title()+’无法与我们共进晚餐。’)

for name in invest_people:

print(‘Hello,Mr ‘+name.title()+’ welcome to my party~’)

print(‘因为找到了一个更大的餐桌,现增加三位嘉宾与我们共进晚餐。’)

invest_people.insert(0,’hui’)

invest_people.insert(3,’xu’)

invest_people.append(‘yan’)

print(‘Now,sending a new invitation to everyone again,the total number of guests is:’+str(len(invest_people)))

for name in invest_people:

print(‘Hello,Mr ‘+name.title()+’ welcome to my party~’)

print(‘因为新订的餐桌无法及时送达,现只能邀请两名嘉宾。’)

pop_guests=[]

i=7

print(invest_people)

while i>0:

pop_guests.append(invest_people.pop())

i=i-1

# print(pop_guests)

# print(invest_people)

for name in pop_guests:

print(‘Sorry,Mr ‘+name.title()+’.因为餐桌无法及时送达,不能邀请您共进晚餐。’)

for name in invest_people:

print(‘Hello,Mr ‘+name.title()+’ you still in my list,welcome to my party~’)

del invest_people[1]

del invest_people[0]

if len(invest_people)==0:

print(‘The list is null’)

#第三章练习题2

travel_places = [‘厦门’,’三亚’,’云南’,’大理’,’青海’,’深圳’,’巴厘岛’,’西安’]

print(travel_places)

print(sorted(travel_places))

print(travel_places)

print(sorted(travel_places,reverse=True))

print(travel_places)

travel_places.reverse()

print(travel_places)

travel_places.reverse()

print(travel_places)

travel_places.sort()

print(travel_places)

travel_places.sort(reverse=True)

print(travel_places)

#大家好,今天是2018年12月17日,天气还不错,我是皮卡丘,这是我看Python编程从入门到实践的第一天,现在是晚上,我敲的是第四章的内容

magicians = [‘alice’,’david’,’carolina’]

for magician in magicians:

print(magician.title()+’,that was a great trick!’)

print(“I can’t wait to see your next trick,”+magician.title()+’.\n’)

print(“Thank you,everyone.That was a great magic show!”)

#第四章练习题1

pizzas = [‘big’,’small’,’middle’,’massive’]

for pizza in pizzas:

print(‘I like ‘+pizza+’ pizza.\n’)

print(‘I really love pizza.’)

even_numbers=list(range(2,11,2))

print(even_numbers)

squares=[]

for value in range(1,11):

squares.append(value**2)

print(squares)

squares_1=[value**2 for value in range(1,11)]

print(squares_1)

#第四章练习题2

for i in range(1,21):

print(i)

list_1=list(range(1,1000001))

# for i in list_1:

# print(i)

if list_1[0]==min(list_1):

print(‘该列表从1开始。’)

if list_1[-1]==max(list_1):

print(‘该列表是到1000000结束。’)

print(‘该列表的总和是:’+str(sum(list_1)))

list_odd=list(range(1,20,2))

for i in list_odd:

print(i)

list_three=[]

for i in range(3,31):

if i%3 == 0:

list_three.append(i)

print(list_three)

list_lifang=[]

for i in range(1,11):

list_lifang.append(i**3)

print(list_lifang)

list_lifang1=[i**3 for i in range(1,11)]

print(list_lifang1)

my_foods=[‘pizza’,’mantou’,’miantiao’]

favorite_foods=my_foods[:]

print(favorite_foods)

friend_foods=my_foods

my_foods.append(‘ice cream’)

friend_foods.append(‘danta’)

print(‘My favorite foods are:’)

print(my_foods)

print(‘My friend favorite foods are:’)

print(friend_foods)

    原文作者:电击小子_ea1b
    原文地址: https://www.jianshu.com/p/1125384a1401
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞