老实说不怎么看得懂
print("Hello Python world!")
prinf("error")
1.会引发
2.理解
3.可以
4.我的经验 你的经验 编译器牛逼
1.siri 小冰 小娜 天猫精灵 live2d交互 多合一 (手写女朋友)就是适用于PC加手机端的 个人信息智能管理系统
2.个人博客移动端
3.论坛移动端
message = input("输入任何数据")
print(message)
message = input("输入任何")
print(message)
Newmessage = input("再次输入任何")
message = Newmessage
print(message)
name = input("输入姓名")
print("hello",name,"!")
name = input("输入姓名")
print(name.upper(),name.lower(),name.title())
name = "alien"
word = " said 'i see,i konw' "
print(name.title()+word)
famous_person = "alien"
message = famous_person.title() +" said 'i see,i konw' "
print(message)
name = "alien \t \n"
print(name.lstrip(),name.rstrip(),name.strip())
print(5+3)
print(9-1)
print(2**3)
print((int)(16/2))
Best_Num = 7
print("我喜欢这个数字",Best_Num)
没啥用 当我写过了
names = ['alien','worli']
for name in names :
print(name.title())
names = ['alien','worli']
for name in names :
print("hello",name,'!')
tools = ['motorcycle','bike']
for tool in tools :
print("like to own a "+ tool + '!')
names = ['alien','linda','mark']
for name in names :
print("我要邀请 "+ name + '一起来吃饭!')
names = ['alien','linda','mark']
for name in names :
print("我要邀请 "+ name + '一起来吃饭!')
print(names[0]+"来不了!")
names[0] = 'wakaka'
for name in names :
print("我要邀请 "+ name + '一起来吃饭!')
names = ['alien','linda','mark']
for name in names :
print("我要邀请 "+ name + '一起来吃饭!')
print(names[0]+"来不了!")
names[0] = 'wakaka'
for name in names :
print("我要邀请 "+ name + '一起来吃饭!')
print("我找到了个更大的饭桌")
names.insert(0,'ladyzhuazhua')
names.insert(len(names)-1,'acac')
names.append('last')
for name in names :
print("我要邀请 "+ name + '一起来吃饭!')
names = ['alien','linda','mark']
for name in names :
print("我要邀请 "+ name + '一起来吃饭!')
print(names[0]+"来不了!")
names[0] = 'wakaka'
for name in names :
print("我要邀请 "+ name + '一起来吃饭!')
print("我找到了个更大的饭桌")
names.insert(0,'ladyzhuazhua')
names.insert(len(names)-1,'acac')
names.append('last')
for name in names :
print("我要邀请 "+ name + '一起来吃饭!')
print("卧槽,我只能邀请两位同学一起吃饭啊!")
for name in names :
if len(names) == 2 :
break
else :
popped_names = names.pop()
print("卧槽 我很抱歉 ",popped_names,"下次约!")
for name in names :
print("嘿",name,"你还在名单上,记得一起哦!")
for i in range(0,2) :
del names[i]
for name in names :
print(name)
places = ['浪漫的土耳其','东京','巴黎','宇宙','银河']
print(places)
print(sorted(places))
print(places)
print(sorted(places,reverse=True))
print(places)
places.reverse()
print(places)
places.reverse()
print(places)
places.sort()
print(places)
places.sort(reverse = True)
print(places)
names = ['alien','linda','mark']
for name in names :
print("我要邀请 "+ name + '一起来吃饭!')
print(names[0]+"来不了!")
names[0] = 'wakaka'
for name in names :
print("我要邀请 "+ name + '一起来吃饭!')
people_num = len(names)
print("一共有",people_num,"个人,过来一起吃饭啊啊!")
list = ['浪漫的土耳其','东京','巴黎','samsara','石原里美']
list.sort()
print(list)
list.sort(reverse = True)
print(list)
print(sorted(list))
print(sorted(list,reverse = True))
list.reverse()
print(list)
print(len(list))
pizzas = ['bnana','cococola','wakaka']
for pizza in pizzas :
print(pizza,"“I like pepperoni pizza”")
print(pizzas,"all best ","“I really love pizza!”")
animals = ['cat','targer','wakaka']
for animal in animals :
print("A",animal,"““ would make a great pet ”")
print("Any of these animals would make a great pet!" )
for value in range(1,21) :
print(value)
num = list(range(1,10000001))
print(num)
numbers = list(range(1,1000001))
print("begin",min(numbers))
print("end",max(numbers))
print("sum",sum(numbers))
q_numbers = list(range(1,21,2))
print(q_numbers)
q_numbers = list(range(3,31,3))
for value in q_numbers :
print(value)
my_list = []
for value in range(1,11) :
q_number = value ** 3
my_list.append(q_number)
for my_value in my_list :
print(my_value)
list = [value ** 3 for value in range(1,11) ]
print(list)
list = [value ** 3 for value in range(1,11) ]
print(list)
print("The first three items in the list are:",list[:3])
print("“Three items from the middle of the list are:",list[3:6])
print("“The last three items in the list are:",list[-3:])
pizzas = ['bnana','cococola','wakaka']
for pizza in pizzas :
print(pizza,"“I like pepperoni pizza”")
print(pizzas,"all best ","“I really love pizza!”")
frined_pizzas = pizzas
frined_pizzas.append('balala')
print(" “My favorite pizzas are:”")
for pizza in pizzas :
print(pizza)
print("“My friend's favorite pizzas are:”")
for pizza in frined_pizzas :
print(pizza)
my_foods = ['pizza', 'falafel', 'carrot cake']
friend_foods = my_foods[:]
my_foods.append('cannoli')
friend_foods.append('ice cream')
print("My favorite foods are:")
print(my_foods)
print("\nMy friend's favorite foods are:")
print(friend_foods)
for food in my_foods :
print(food)
for food in friend_foods:
print(food)
foods = ('pizza','bnana','wakaka','旋风无敌草莓圣代','爷爷可高兴的喜之郎')
for food in foods:
print(food)
foods = ('newewpizza','bnana','wakaka','旋风无敌草莓圣代','奶奶她也很高兴的喜之郎')
for food in foods:
print(food)
car = 'subaru'
print("Is car == 'subaru'? I predict True.")
print(car == 'subaru')
print("\nIs car == 'audi'? I predict False.")
print(car == 'audi')
if car == 'subaru':
print("True")
if car != 'subaru':
print("Flase")
pizza = 'cool'
if pizza == 'cool':
print(True)
else :
print(False)
cat = '噬元兽'
if cat == '噬元兽':
print(True)
else :
print(False)
t = 1
if t == 1 :
print(True)
else :
print(False)
alien = '外星人'
if alien == '外星人' :
print(True)
else :
print(False)
space = '重庆最好的蹦迪九八'
if space == '重庆最好的蹦迪九八':
print(True)
else :
print(False)
a = ['13213516546','14444866843']
c =['21443514646']
u_a = '14444866843'
u_c = '4567837378'
if a[1].lower() == u_c and u_a in a or u_a not in u_a:
print(True)
else:
print(False)
alien_color = 'yellow'
if alien_color == 'green':
print(True)
else:
print(False)
alien_color = 'green'
if alien_color == 'green':
print(True)
alien_color = 'blue'
if alien_color == 'green':
print('你干掉了他,获得了5个点')
else:
print('你获得了十个点')
alien_color = 'blue'
if alien_color == 'green':
print('你干掉了他,获得了5个点')
if alien_color != 'green':
print('你获得了十个点')
alien_color = 'blue'
if alien_color == 'green':
print('你干掉了他,获得了5个点')
elif alien_color == 'red':
print('你获得了十个点')
elif alien_color == 'yellow':
print('你获得了15个点')
age = 155155348
if age < 2:
print("你就是个婴儿")
elif age >2 and age <4:
print("你怕不是蹒跚学步")
elif age >4 and age <13:
print("你就是个儿童")
elif age >13 and age <20:
print("你就是个青少年")
elif age >20 and age <65:
print("你就是个成年人")
elif age >65:
print("你就是个老年人")
favorite_fruits = ['banana','apple','dokiki','wakaka','balala']
if 'banana' in favorite_fruits:
print('banana You really like bananas!')
if 'apple' in favorite_fruits:
print('apple You really like apple!')
if 'wakaka' in favorite_fruits:
print('wakaka You really like wakaka!')
if 'balala' in favorite_fruits:
print('balala You really like balala!')
if 'dokiki' in favorite_fruits:
print('dokiki You really like dokiki!')
names = ['admin','小李','晓红','肖黄','小吕']
for name in names :
if name == 'admin':
print( "“Hello admin, would you like to see a status report?")
else:
print(name,'hello',"thank you for logging in again")
names = ['admin','小李','晓红','肖黄','小吕']
for i in range(0,len(names)) :
names.pop()
if names:
for name in names :
if name == 'admin':
print( "“Hello admin, would you like to see a status report?")
else:
print(name,'hello',"thank you for logging in again")
else:
print("“We need to find some users!")
current_users = ['admin','小李','晓红','肖黄','小吕']
new_users = ['admin','小惠','晓红','协和','男科']
for name in new_users :
if name in current_users:
print('sorry',name,'you need found an other name !')
numbers = [number for number in range (1,11)]
for number in numbers:
if number == 1:
print("1st")
elif number == 2:
print("2rd")
elif number == 3:
print("3随便是什么d")
else:
print(number,"th")
应该是没错
1.siri 小冰 小娜 三个方向三合一的 伪智能机器人
2.个人网站移动端APP
3.游戏啊 就是 就是一那个那样吧 其实 这两个可以合二为一
zhengzhi = {
'姓':"郑",
"名":"治",
'年龄':"??",
"居住的城市":"wakawaka"
}
print(zhengzhi)
a = {
'name':'a',
'num': '1'
}
b = {
'name':'b',
'num': '2'
}
c = {
'name':'c',
'num': '3'
}
d = {
'name':'d',
'num': '4'
}
e = {
'name':'e',
'num': '5'
}
print(a['name'],a['num'])
print(b['name'],b['num'])
print(c['name'],c['num'])
print(d['name'],d['num'])
print(e['name'],e['num'])
p = {
'int' : '整型',
'float':"浮点形",
'double':"双浮点",
'string':"字符串",
'char':"单字符",
"longlong":"双长"
}
for v,k in p.items():
print(v,k)
p = {
'int' : '整型',
'float':"浮点形",
'double':"双浮点",
'string':"字符串",
'char':"单字符",
"longlong":"双长",
'print()':"输出",
"list":"表格",
"elif":"除了 如果",
"字典":"字典就是字典啊",
"元组":"元组就是元组啊"
}
for v,k in p.items():
print(v,k)
rivers = {
'nile': 'egypt',
"长江":"china",
"恒河":"印度",
"尼罗河":"埃及",
"巴黎水":"巴黎"
}
for river,place in rivers.items():
print("the",river,"runs through ",place)
favorite_languages = {
'jen': 'python',
'sarah': 'c',
'edward': 'ruby',
'phil': 'python',
}
for name, language in favorite_languages.items():
print(name.title() + "'s favorite language is " +
language.title() + ".")
peoples = ['jen','balala','sarah']
for people in peoples:
print(people,'\n')
if people in favorite_languages:
print("thanks")
else:
print("invite you to join us")
zhengzhi = {
'姓':"郑",
"名":"治",
'年龄':"??",
"居住的城市":"wakawaka"
}
ladyzhuazhua = {
'姓名':"石原里美",
'年龄':"18",
"居住的城市":"日本"
}
wakawaka = {
'姓名':"aputon",
'年龄':"18",
"居住的城市":"巴黎"
}
list = []
list.append(zhengzhi)
list.append(ladyzhuazhua)
list.append(wakawaka)
print(list)
popo = {
"种类":"是一条是狗",
"主人":"旺旺小码头"
}
cici = {
"种类":"是一条是猫猫",
"主人":"我老婆石原里美"
}
pets = []
pets.append(popo)
pets.append(cici)
print(pets)
favorite_places = {
"十元里美":["东京",'中国'],
"wakaka":["扶轮利达",'塞卡',"瓦克"],
"安提歌哥哥":["巴达罗",'东和'],
}
for name,place in favorite_places.items():
print(name,place)
a = {
'name':'a',
'num':['41','546','486406']
}
b = {
'name':'b',
'num': ['535','464']
}
c = {
'name':'c',
'num': ['35453','468464']
}
d = {
'name':'d',
'num': ['4546']
}
e = {
'name':'e',
'num': ['64684','534654']
}
print(a['name'],a['num'])
print(b['name'],b['num'])
print(c['name'],c['num'])
print(d['name'],d['num'])
print(e['name'],e['num'])
cities = {
"浪漫的土耳其":{
"国家":"tuerqi",
"人口约数":"1000000",
"事实":"浪漫的"
},
"东京":{
"国家":"日本",
"人口约数":"1000000",
"事实":"樱花秒速五厘米"
},
"巴黎":{
"国家":"法国",
"人口约数":"1000000",
"事实":"巴黎水真的喝不来"
}
}
print(cities)
cities = {
"浪漫的土耳其":{
"国家":"tuerqi",
"人口约数":"1000000",
"事实":"浪漫的"
},
"东京":{
"国家":"日本",
"人口约数":"1000000",
"事实":"樱花秒速五厘米"
},
"巴黎":{
"国家":"法国",
"人口约数":"1000000",
"事实":"巴黎水真的喝不来"
}
}
for citie,info in cities.items() :
long_p = info[" 国家 "]+info["人口约数"]+info["事实"]
print(citie + long_p)
car = input("你要租一个什么样的车车?")
print("Let me see if I can find you a ",car)
num = int(input("有多少个人吃饭啊?"))
if num >8 :
print("摸得位子得")
else:
print("请请请")
num = input("随便输入一个数字,我会指出是不是 10 的倍数")
num = int(num)
if num % 10 == 0:
print(True)
else:
print(False)
pizza = []
while True:
new = input("输入一个配料")
if new == 'quit':
break;
else:
pizza.append(new)
print("我们会添加",new,"这种配料")
age = input("你多少岁了?")
age = int(age)
if age <3 :
print("免费哦")
elif age>3 and age<12:
print("收你10美元")
else:
print("收你15元")
pizza = []
active = False
while True:
new = input("输入一个配料")
if new == 'quit':
active = True
if active:
break;
else:
pizza.append(new)
print("我们会添加",new,"这种配料")
while 1 :
print("COOL_Z")
sandwich_orders = ['balala','wakaka','blili']
finished_sandwiches = []
for order in sandwich_orders:
print("I made your", order," sandwich ")
finished_sandwiches.append(order)
for order in sandwich_orders:
print(order)
for order in finished_sandwiches:
print(order)
sandwich_orders = ['balala','wakaka','blili','pastrami' ,'pastrami' ,'pastrami' ]
print("熟食店的五香烟熏牛肉卖完了")
while 'pastrami' in sandwich_orders:
sandwich_orders.remove('pastrami')
if 'pastrami' not in sandwich_orders:
print( 'pastrami' ,"没在里面啊")
places = []
while 1:
place = input("“If you could visit one place in the world, where would you go?” ")
if place == 'quit':
break
else :
places.append(place)
continue
print(places)
def display_message():
print("学自定义函数哦!")
display_message()
def favorite_book(title):
print("One of my favorite books is",title)
favorite_book("threekindom")
def make_shirt():
size = input("你要的尺码")
word = input("你要印刷的字样")
print("这件衣服大",size,"字样",word)
make_shirt()
def make_shirt(size='XXL',word='I love Python'):
print("这件衣服大",size,"字样",word)
make_shirt()
make_shirt(word = 'wakka')
def describe_city(place = '天上人间',contry = '华夏'):
print(place," is in",contry)
describe_city()
describe_city(place = 'wakaka')
describe_city(contry = "wanck")
def city_country(city,country):
new_p = city +country
return new_p
q = []
q.append(city_country('adcv ',' asbf'))
q.append(city_country('ababfr ',' crgq e'))
q.append(city_country('cwhve ',' c35v4'))
for k in q :
print(k)
def make_album(sigger,album):
q = sigger + album
return q
p =[]
p.append(make_album("v","QEGR"))
p.append(make_album("T"," QRG"))
p.append(make_album("G","WTXWGR"))
print(p)
def make_album(sigger,album):
q = sigger +" "+ album
return q
p =[]
while 1:
new_sigger = input("输入歌手")
new_album = input("输入专辑")
if new_sigger == 'q' or new_album == 'q':
break
else:
p.append(make_album(new_sigger,new_album))
print(p)
list = ["大卫","刘谦","哈利波特"]
def make_great():
list[0] = "the greet 大卫"
list[1] = "the greet刘谦"
list[2] = "the greet哈利波特"
def show_magicians(name):
print("现在让我们欢迎宇宙无敌可亲可爱天下第一的",name)
make_great()
show_magicians(list)
list = ["大卫","刘谦","哈利波特"]
def make_great(list):
global new_list
new_list = []
for name in list:
new_list.append("the great"+name)
def show_magicians(name):
print("现在让我们欢迎宇宙无敌可亲可爱天下第一的",name)
make_great(list)
show_magicians(new_list)
list = ["大卫","刘谦","哈利波特"]
def make_great(list):
global new_list
new_list = []
for name in list:
new_list.append("the great"+name)
def show_magicians(name):
print("现在让我们欢迎宇宙无敌可亲可爱天下第一的",name)
make_great(list)
show_magicians(list)
show_magicians(new_list)
def diy_sand (*any):
print("你想吃的三明治包含以下素材",any)
diy_sand("蒸熊掌","鱼子酱")
diy_sand("鹿肉")
diy_sand("小鸟酱")
def build_profile(first, last, **user_info):
profile = {}
profile['first_name'] = first
profile['last_name'] = last
for key, value in user_info.items():
profile[key] = value
return profile
user_profile = build_profile('郑', '治',
location='重庆',
field='计算机',
something="单身二十年"
)
print(user_profile)
def make_car (model,manu,**info):
file = {}
file['model'] = model
file['manu'] = manu
for key,value in info.items():
file[key] = value
return file
car = make_car('subaru', 'outback', color='blue', tow_package=True)
print(car)
printing_functions.py
unprinted_designs = ['iphone case', 'robot pendant', 'dodecahedron']
completed_models = []
while unprinted_designs:
current_design = unprinted_designs.pop()
print("Printing model: " + current_design)
completed_models.append(current_design)
print("\nThe following models have been printed:")
for completed_model in completed_models:
print(completed_model)
print_models.py
import printing_functions as p
p
printing_functions.py
def do ():
unprinted_designs = ['iphone case', 'robot pendant', 'dodecahedron']
completed_models = []
while unprinted_designs:
current_design = unprinted_designs.pop()
print("Printing model: " + current_design)
completed_models.append(current_design)
print("\nThe following models have been printed:")
for completed_model in completed_models:
print(completed_model)
main.py
import printing_functions as p
from printing_functions import do
from printing_functions import do as fn
import printing_functions as mn
from printing_functions import *
p
do()
fn()
mn
do()
双峰命名法 缩进 空格 还是 认真的时候有好好注意的
class Restaurant():
def __init__(self,restaurant_name,cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print(self.restaurant_name,self.cuisine_type)
def open_restaurant(self):
print(self.restaurant_name,"正在营业")
a_restaurant = Restaurant("蟹堡黄","汉堡包包店")
a_restaurant.open_restaurant()
a_restaurant.describe_restaurant()
class Restaurant():
def __init__(self,restaurant_name,cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print(self.restaurant_name,self.cuisine_type)
def open_restaurant(self):
print(self.restaurant_name,"正在营业")
a_restaurant = Restaurant("蟹堡黄","汉堡包包店")
b_restaurant = Restaurant("早餐中国加盟商","西餐厅")
c_restaurant = Restaurant("正宗法式早茶店","居酒屋")
a_restaurant.describe_restaurant()
b_restaurant.describe_restaurant()
c_restaurant.describe_restaurant()
class uers():
def __init__(self, first_name, last_name,descireb,number):
self. first_name = first_name
self. last_name = last_name
self. descireb = descireb
self. number = number
def describe_user(self):
print(self.first_name + self.last_name,self.descireb,self.number)
def greet_user(self):
print('hello',self.first_name + self.last_name)
a = uers("黄","蛤","风干镇","100210")
b = uers("何","丽丽","很热镇","468464")
c = uers("堡","嘁嘁嘁","姜山","195210")
a.greet_user()
a.describe_user()
b.greet_user()
b.describe_user()
c.greet_user()
c.describe_user()
class Restaurant():
def __init__(self,restaurant_name,cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print(self.restaurant_name,self.cuisine_type)
def open_restaurant(self):
print(self.restaurant_name,"正在营业")
def set_number_severed (self,num):
print("只接待",num,"个人")
def increment_number_served(self,num):
print("我觉得这么牛逼的餐厅每天起码得接待",num,"个人")
a_restaurant = Restaurant("蟹堡黄","汉堡包包店")
a_restaurant.open_restaurant()
a_restaurant.describe_restaurant()
a_restaurant.set_number_severed(10)
a_restaurant.increment_number_served(90)
class uers():
def __init__(self, first_name, last_name,descireb,number, login_attempts):
self. first_name = first_name
self. last_name = last_name
self. descireb = descireb
self. number = number
self. login_attempts = login_attempts
def describe_user(self):
print(self.first_name + self.last_name,self.descireb,self.number)
def greet_user(self):
print('hello',self.first_name + self.last_name)
def increment_login_attempts(self):
self.login_attempts += 1
def reset_login_attempts(self):
self. login_attempts = 0
a = uers("黄","蛤","风干镇","100210",0)
a.increment_login_attempts()
a.increment_login_attempts()
a.increment_login_attempts()
print(a.login_attempts)
a.reset_login_attempts()
print(a.login_attempts)
class Restaurant():
def __init__(self,restaurant_name,cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print(self.restaurant_name,self.cuisine_type)
def open_restaurant(self):
print(self.restaurant_name,"正在营业")
def set_number_severed (self,num):
print("只接待",num,"个人")
def increment_number_served(self,num):
print("我觉得这么牛逼的餐厅每天起码得接待",num,"个人")
class IceCreamStand (Restaurant) :
def __init__(self,restaurant_name,cuisine_type):
super().__init__(restaurant_name,cuisine_type)
self. flavors = []
def display_flavors(self):
print(self.flavors)
p = IceCreamStand("啊根大肆","流行冰淇淋")
p.flavors.append("香草")
p.flavors.append("菊花")
p.flavors.append("溜溜")
p.display_flavors()
class uers():
def __init__(self, first_name, last_name,descireb,number, login_attempts):
self. first_name = first_name
self. last_name = last_name
self. descireb = descireb
self. number = number
self. login_attempts = login_attempts
def describe_user(self):
print(self.first_name + self.last_name,self.descireb,self.number)
def greet_user(self):
print('hello',self.first_name + self.last_name)
def increment_login_attempts(self):
self.login_attempts += 1
def reset_login_attempts(self):
self. login_attempts = 0
class Admin(uers):
def __init__(self,first_name, last_name,descireb,number, login_attempts):
super().__init__(first_name, last_name,descireb,number, login_attempts)
self. privileges = []
def show_privileges(self):
print(self.privileges)
Z = Admin("郑","治","重庆","18105756",0)
Z.privileges.append("can add post")
Z.privileges.append("can delete post")
Z.privileges.append("can ban user")
Z.show_privileges()
class uers():
def __init__(self, first_name, last_name,descireb,number, login_attempts):
self. first_name = first_name
self. last_name = last_name
self. descireb = descireb
self. number = number
self. login_attempts = login_attempts
def describe_user(self):
print(self.first_name + self.last_name,self.descireb,self.number)
def greet_user(self):
print('hello',self.first_name + self.last_name)
def increment_login_attempts(self):
self.login_attempts += 1
def reset_login_attempts(self):
self. login_attempts = 0
class Privileges():
def __init__(self,privileges = ["can add post","can delete post","can ban user"]):
self.privileges = privileges
def show_privileges(self):
print(self.privileges)
class Admin(uers):
def __init__(self,first_name, last_name,descireb,number, login_attempts):
super().__init__(first_name, last_name,descireb,number, login_attempts)
self. privileges = []
self.display = Privileges()
Z = Admin("郑","治","重庆","18105756",0)
Z.display.show_privileges()
class Car():
""" 一次模拟汽车的简单尝试 """
def __init__(self, make, model, year):
self.make = make
self.model = model
self.year = year
self.odometer_reading = 0
def get_descriptive_name(self):
long_name = str(self.year) + ' ' + self.make + ' ' + self.model
return long_name.title()
def read_odometer(self):
print("This car has " + str(self.odometer_reading) + " miles on it.")
def update_odometer(self, mileage):
if mileage >= self.odometer_reading:
self.odometer_reading = mileage
else:
print("You can't roll back an odometer!")
def increment_odometer(self, miles):
self.odometer_reading += miles
class ElectricCar(Car):
""" 电动汽车的独特之处 """
def __init__(self, make, model, year):
super().__init__(make, model, year)
class Battery():
def __init__(self, battery_size=70):
self.battery_size = battery_size
def describe_battery(self):
print("This car has a " + str(self.battery_size) + "-kWh battery.")
def get_range(self):
if self.battery_size == 70:
range = 240
elif self.battery_size == 85:
range = 270
message = "This car can go approximately " + str(range)
message += " miles on a full charge."
print(message)
def upgrade_battery(self):
if self.battery_size != 85:
self.battery_size = 85
class ElectricCar(Car):
def __init__(self, make, model, year):
super().__init__(make, model, year)
self.battery = Battery()
super_moto = ElectricCar("中央之国","云鲸","2020")
super_moto.battery.get_range()
super_moto.battery.upgrade_battery()
super_moto.battery.get_range()
Restaurant.py
class Restaurant():
def __init__(self,restaurant_name,cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print(self.restaurant_name,self.cuisine_type)
def open_restaurant(self):
print(self.restaurant_name,"正在营业")
main.py
from Restaurant import *
my_Restaurant =Restaurant("咬金","风味中餐厅")
my_Restaurant.open_restaurant()
web.py
class uers():
def __init__(self, first_name, last_name,descireb,number, login_attempts):
self. first_name = first_name
self. last_name = last_name
self. descireb = descireb
self. number = number
self. login_attempts = login_attempts
def describe_user(self):
print(self.first_name + self.last_name,self.descireb,self.number)
def greet_user(self):
print('hello',self.first_name + self.last_name)
def increment_login_attempts(self):
self.login_attempts += 1
def reset_login_attempts(self):
self. login_attempts = 0
class Privileges():
def __init__(self,privileges = ["can add post","can delete post","can ban user"]):
self.privileges = privileges
def show_privileges(self):
print(self.privileges)
main.py
class Admin(uers):
def __init__(self,first_name, last_name,descireb,number, login_attempts):
super().__init__(first_name, last_name,descireb,number, login_attempts)
self. privileges = []
self.display = Privileges()
from web import *
z = Admin("郑","治","重庆","18105756",0)
z. display.show_privileges()
web_users.py
class uers():
def __init__(self, first_name, last_name,descireb,number, login_attempts):
self. first_name = first_name
self. last_name = last_name
self. descireb = descireb
self. number = number
self. login_attempts = login_attempts
def describe_user(self):
print(self.first_name + self.last_name,self.descireb,self.number)
def greet_user(self):
print('hello',self.first_name + self.last_name)
def increment_login_attempts(self):
self.login_attempts += 1
def reset_login_attempts(self):
self. login_attempts = 0
show_others.py
from web_users import *
class Privileges():
def __init__(self,privileges = ["can add post","can delete post","can ban user"]):
self.privileges = privileges
def show_privileges(self):
print(self.privileges)
class Admin(uers):
def __init__(self,first_name, last_name,descireb,number, login_attempts):
super().__init__(first_name, last_name,descireb,number, login_attempts)
self. privileges = []
self.display = Privileges()
main.py
from web_users import *
from web_others import *
z = Admin("郑","治","重庆","18105756",0)
z.display.show_privileges()
from collections import OrderedDict
p = OrderedDict()
p['int'] = '整型',
p['float'] = "浮点形",
p['double'] = "双浮点",
p['string'] = "字符串",
p['char'] = "单字符",
p['longlong'] = "双长",
p['print()'] = "输出",
p['list'] = "表格",
p['elif'] = "除了 如果",
p['字典'] = "字典就是字典啊",
p['元组'] = "元组就是元组啊"
for v,k in p.items():
print(v,k)
from random import randint
class Die ():
def __init__(self,sides=6):
self.sides = sides
def roll_die(self):
num = randint(1,self.sides)
print(num)
p = Die(6)
q = Die(10)
k = Die(20)
for i in range (1,11):
p.roll_die()
q.roll_die()
k.roll_die()
mark了 下次再看看吧 我先把你刷完
file_name = 'learning_python.txt'
file_object= open(file_name,'r', encoding='UTF-8')
content = file_object.read()
print(content)
for line in file_object:
print(line)
lines = file_object.readlines()
for line in lines:
print(line.rstrip())
file_name = 'learning_python.txt'
with open (file_name) as f:
content = f.readlines()
for line in content:
new_line = line.replace('Python','C')
print(new_line.rstrip())
file_name = 'guest.txt'
with open(file_name,'w') as f:
while 1:
p = input("输入你的名字")
if p == 'q':
break
else:
f.write(p)
file_name = 'learning_python.txt'
with open(file_name,'w') as f :
while 1:
p = input("输入信息")
if p == 'q':
break;
else:
f.write(p)
f.write('\n')
file_name = 'guest.txt'
with open (file_name,'w+') as f:
while 1:
p = input("你为什么喜欢编程")
if p == 'q':
break
else:
f.write(p)
def p ():
try:
i = int(input())
j = int(input())
except ValueError:
msg = '请输入两个数字'
print(msg)
else:
print(i+j)
p()
def p ():
while 1:
try:
i = int(input())
j = int(input())
except ValueError:
msg = '请输入两个数字'
print(msg)
else:
print(i+j)
p()
file_cats = 'cat.txt'
file_dogs = 'dog.txt'
try:
with open(file_cats,'r') as object_cats:
print(object_cats.read())
with open(file_dogs,'r') as object_dogs:
print(object_dogs.read())
except FileNotFoundError:
print("没发现文件")
file_cats = 'cat.txt'
file_dogs = 'dog.txt'
try:
with open(file_cats,'r') as object_cats:
print(object_cats.read())
with open(file_dogs,'r') as object_dogs:
print(object_dogs.read())
except FileNotFoundError:
pass
file_name = 'test_book.txt'
try:
with open(file_name) as f_obj:
content = f_obj.read()
content = content.lower()
except FileNotFoundError:
print("未发现文件")
else:
num = content.count('the')
print(num)
import json
file_name = 'numbers.json'
try:
with open(file_name) as f_obj:
except FileNotFoundError:
print("没发现文件")
else:
username = input("输入你的名字")
json.dump(username,f_obj)
name = json.load(filename)
print("“I know your favorite number! It's _____.”",name)
import json
file_name='numbers.json'
username = input("输入你喜欢的数字")
try:
with open(file_name,'w') as f_obj:
json.dump(username,f_obj)
except FileNotFoundError:
print("Error")
else:
with open(file_name) as f_obj:
name = json.load(f_obj)
print("“I know your favorite number! It's _____.”",name)
import json
file_name='numbers.json'
try:
with open(file_name) as f_obj:
name = json.load(f_obj)
print("“I know your favorite number! It's _____.”",name)
flag = False
except FileNotFoundError:
print("Error")
else:
if (flag):
username = input("输入你喜欢的数字")
with open(file_name,'w') as f_obj:
json.dump(username,f_obj)
import json
filename = 'username.json'
def greet_new_name():
username = input("What is your name? ")
with open(filename, 'w') as f_obj:
json.dump(username, f_obj)
with open(filename,'r') as f_obj:
username = f_obj.read()
return(username)
def get_username():
try:
with open(filename,'r') as f_obj:
username = f_obj.read()
except FileNotFoundError:
greet_new_name()
else:
return(username)
def greet_user():
name = get_username()
if name:
try:
with open(filename) as f_obj:
username = json.load(f_obj)
except FileNotFoundError:
print("not found!")
else:
print("Welcome back, " + username + "!")
else:
greet_new_name()
greet_user()
city_functions.py
def get_city_country(city,country):
full_name = city+" "+country
return full_name.title()
mian.py
import unittest
from city_functions import *
class CityCountryTestCase(unittest.TestCase):
def test_city_country(self):
city_country = get_city_country("santiago","chile")
self.assertEqual(city_country,"Santiago Chile")
unittest.main()
city_functions.py
def get_city_country(city,country,populution):
full_name = city+','+country +'-population'+" "+str(populution)
return full_name.title()
maim.py
import unittest
from city_functions import *
class CityCountryTestCase(unittest.TestCase):
def test_city_country(self):
city_country = get_city_country("santiago","chile",5000000)
self.assertEqual(city_country,"Santiago,Chile-Population 5000000")
def test_city_country_population(self):
city_country_country = get_city_country("santiago","chile",5000000)
self.assertEqual(city_country_country,"Santiago,Chile-Population 5000000")
unittest.main()
import unittest
import unittest
class Employee():
def __init__(self,first_name,last_name,annual_pay):
self.first_name = first_name
self.last_name = last_name
self.annual_pay = annual_pay
def give_raise(self):
self.annualpay = 5000
return self.annualpay
class test_EmployeeTestCase(unittest.TestCase) :
def setUp(self):
self.Employee = Employee('王','小明',300)
def test_give_default_raise(self):
self.assertEqual(self.Employee.annual_pay,300)
def test_give_custom_raise(self):
self.assertEqual(self.Employee.give_raise(),5000)
unittest.main()
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本