Hello World.py
print("Hello World")
message = "Hello Python Crash Course World!"
print(message)
name.py
name = "ada lovelace"
print(name.title())
print(name.upper())
print(name.lower())
full_name.py
first_name = "ada"
last_name = "lovelace"
full_name = f"{first_name} {last_name}"
print(full_name)
print(f"Hello,{full_name.title()}!")
message = f"Hello,{full_name.title()}!"
print(message)
opostrophe.py
message = "One of python's strengths is its diverse community."
print(message)
name_cases.py
name = "Eric"
message = f"Hello {name},would you like to learn some Python today?"
print(message)
name_cases1.py
name = "Zhong guo"
print(name.title())
print(name.upper())
print(name.lower())
famous_person.py
print('Albert Einstein once said,"A person who never made a mistake never tried anything new."')
famous_person1.py
famous_person = "Albert Einstein"
msg = 'once said,"A person who never made a mistake never tried anything new."'
print(f"{famous_person} {msg}")
name_trip.py
name = "\tAlbert Einstein\n"
print("For example:")
print(name)
print("\nusing trip():")
print(name.strip())
print("\nusing lstrip():")
print(name.lstrip())
print("\nusing rstrip():")
print(name.rstrip())
math.py
print(1+7)
print(9-1)
print(2*4)
print(16/2)
favorite_number.py
#输出最喜欢的数
fav_number = 666
msg = f"My favorite number is {fav_number}."
print(msg)
comment.py
#向大家问好。
print("Hello Python people!")
The zen of Python.py
#Python之禅
import this
bicycles.py
bicycles = ['trek','cannondale','redline','specialized']
print(bicycles[-1].title())
message = f"My first bicycle was a {bicycles[0].title()}."
print(message)
name_friend.py
#3-1姓名:将一些朋友的姓名存储在一个列表中,并将其命名为names。依次访问该列表中的每个元素,从而将每个朋友的姓名都打印出来。
names = ['yuki','sakura','yamaha','kalazan']
print(names[0])
print(names[1])
print(names[2])
print(names[3])
print(names[-1].title())
name_friend1.py
#3-2问候语:不打印每个朋友的姓名,而为每人打印一条消息。
#每条消息都包含相同的问候语,但抬头为相应的朋友姓名。
names = ['yuki','sakura','yamaha','kalazan']
message = f"Hello,nice to meet you,{names[0].title()}!"
print(message)
message = f"Hello,nice to meet you,{names[1].title()}!"
print(message)
message = f"Hello,nice to meet you,{names[2].title()}!"
print(message)
message = f"Hello,nice to meet you,{names[3].title()}!"
print(message)
commuting_mode.py
#3-3自己的列表:想想你喜欢的通勤方式,如骑摩托车或开汽车,并创建一个包含多种通勤方式的列表。根据该列表打印一系列有关这些通勤方式的宣言
#如:I would like to own a Honda motorcycle.
commuting_mode = ['bicycle','motorcycle','car']
message = f"I would like to own a {commuting_mode[0].title()}."
print(message)
motocycles.py
motorcycles = ['honda','yamaha','suzuki']
print(motorcycles)
motorcycles[0] = 'ducati'
print(motorcycles)
motorcycles.append('honda')
print(motorcycles)
append.py
motorcycles = []
motorcycles.append('honda')
motorcycles.append('yamaha')
motorcycles.append('suzuki')
print(motorcycles)
insert.py
motorcycles = ['honda','yamaha','suzuki']
motorcycles.insert(1,'ducati')
print(motorcycles)
del.py
motorcycles = ['honda','yamaha','suzuki']
print(motorcycles)
del motorcycles[0]
print(motorcycles)
pop.py
motorcycles = ['honda','yamaha','suzuki']
print(motorcycles)
popped_motorcycle = motorcycles.pop()
print(motorcycles)
print(popped_motorcycle)
first_owned.py
motorcycles = ['honda','yamaha','suzuki']
first_owned = motorcycles.pop()
print(f"The first motorcycle I owned was a {first_owned.title()}.")
remove.py
motorcycles = ['honda','yamaha','suzuki','ducati']
print(motorcycles)
motorcycles.remove('ducati')
print(motorcycles)
motorcycles = ['honda','yamaha','suzuki','ducati']
print(motorcycles)
too_expensive = 'ducati'
motorcycles.remove(too_expensive)
print(motorcycles)
print(f"\nA {too_expensive.title()} is too expensive for me.")
guests.py
#如果你可以邀请任何人共进晚餐(无论是故去的还是在世的),你会邀请哪些人?请
#创建一个列表,其中包含至少三个你想邀请的人;然后,使用这个列表打印消息,邀请这
#些人来与你共进晚餐。
guests = ['yuki','sakura','kalazan']
# 邀请嘉宾与你共进晚餐。
name = guests[0].title()
print(f"{name},please come to dinner.")
name = guests[1].title()
print(f"{name},please come to dinner.")
name = guests[2].title()
print(f"{name},please come to dinner.")
#指出其中一位嘉宾无法赴约。
name = guests[1].title()
print(f"\nSorry,{name} can't make it to dinner.")
#修改嘉宾名单,替换无法赴约嘉宾为新邀请嘉宾姓名。
del(guests[1])
guests.insert(1,'kuraki')
#重新邀请嘉宾与你共进晚餐。
name = guests[0].title()
print(f"\n{name},please come to dinner.")
name = guests[1].title()
print(f"{name},please come to dinner.")
name = guests[2].title()
print(f"{name},please come to dinner.")
#找到了更大的餐桌,再邀请三位嘉宾。
print("\nWe got a bigger table!")
guests.insert(0,'yutada')
guests.insert(2,'boa')
guests.append('kaori')
name = guests[0].title()
print(f"\n{name},please come to dinner.")
name = guests[1].title()
print(f"{name},please come to dinner.")
name = guests[2].title()
print(f"{name},please come to dinner.")
name = guests[3].title()
print(f"{name},please come to dinner.")
name = guests[4].title()
print(f"{name},please come to dinner.")
name = guests[5].title()
print(f"{name},please come to dinner.")
#餐桌无法及时送达,
print("\nSorry,we can only invite two people to dinner.")
name = guests.pop()
print(f"Sorry,{name.title()} there's no room at the table.")
name = guests.pop()
print(f"Sorry,{name.title()} there's no room at the table.")
name = guests.pop()
print(f"Sorry,{name.title()} there's no room at the table.")
name = guests.pop()
print(f"Sorry,{name.title()} there's no room at the table.")
print(len(name))
cars.py
cars = ['bmw','audi','toyota','subaru']
cars.sort()
print(cars)
cars.sort(reverse=True)
print(cars)
cars_sorted.py
cars = ['bmw','audi','toyota','subaru']
print("Here is the original list:")
print(cars)
print("\nHere is the sorted list:")
print(sorted(cars))
print("\nHere is the original list again:")
print(cars)
cars.reverse()
print(cars)
print(len(cars))
locations.py
#3-8列出渴望去的五个地方
locations = ['japan','hongkong','xizang','himalaya','korean']
#按原始排列顺序打印列表
print("Original order:")
print(locations)
#使用sorted()按字母顺序打印列表
print("\nAlphabetical:")
print(sorted(locations))
#再次打印列表进行核实顺序未变
print("\nOriginal order:")
print(locations)
#使用sorted()临时按字母顺序相反的顺序打印列表,不修改列表。
print("\nReverse alphabetical:")
print(sorted(locations,reverse=True))
#再次打印列表进行核实顺序未变
print("\nOriginal order:")
print(locations)
#使用reverse()修改列表元素排列顺序,并打印核实
print("\nReversed:")
locations.reverse()
print(locations)
#使用reverse()再次修改列表元素排列顺序,打印并核实已恢复到原来的排序。
print("\nOriginal order:")
locations.reverse()
print(locations)
#使用sort()修改列表,按字母顺序排列并打印核实
print("\nAlphabetical:")
locations.sort()
print(locations)
#使用sort()修改列表,使其元素按字母顺序相反的顺序排列,打印并核实
print("\nReverse alphabetical:")
locations.sort(reverse=True)
print(locations)