# -*- coding = utf - 8 -*-
#大家好,今天是2018年12月21日,有点阴天,我是皮卡丘,这是我看Python编程从入门到实践的第二天,现在是上午,我敲的是第五章的内容
#第五章的练习题2
car = 'subaru'
print('if car==subaru?Is my predicition True?'+str(car=='subaru'))
print('if car==audi?Is my predicition True?')
print(car=='audi')
#第五章的练习题3
print('Please input the color of alien:green|red|yellow')
alien_color = input()
if alien_color == 'green':
print('The color of the alien that you killed is green,so you got five points.')
elif alien_color == 'red':
print('The color of the alien that you killed is red,so you got ten points.')
elif alien_color == 'yellow':
print('The color of the alien that you killed is yellow,so you got zero point.')
else:
print('请输入红色、黄色、绿色三种颜色的其中一种,你的输入格式错误。')
fruits = ['apple','pea','tomato','banana']
if 'apple' in fruits:
print("I really like apples.")
if 'banana' in fruits:
print('I really like bananas.')
if 'huanggua' not in fruits:
print('Huanggua is not fruit.')
#第五章的练习题4
users = ['admin','pikaqiu','zhang','liu','wang']
for user in users:
if user == 'admin':
print('Hello admin,would you like to see a status report?')
else:
print('Hello '+user+',thank you for logging in again')
if not users:
print('We need to find some users')
current_users=['admin','pikaqiu','zhang','liu','WanG','xue']
current_users1=[user.lower() for user in current_users]#使程序不区分大小写
new_users=['admin','wang','san','si','xue']
for user in new_users:
if user.lower() in current_users1:
if user == 'admin':
print('这是管理员,不能注册,请输入其他用户名。')
else:
print('该用户名已被使用,请输入其他用户名。')
else:
print('该用户名可用,注册成功。')
num = [i for i in range(1,10)]
for i in num:
if i == 1:
print(str(i)+'st')
elif i == 2:
print(str(i)+'nd')
elif i == 3:
print(str(i)+'rd')
else:
print(str(i)+'th')
#大家好,今天是2018年12月21日,有点阴天,我是皮卡丘,这是我看Python编程从入门到实践的第二天,现在是下午,我敲的是第六章的内容
#第六章练习题1
one_friend = {'姓氏':'张','名字':'胜天','性别':'男','年龄':'27',}
for i in one_friend.values():
print(i)
favorite_num = {'王菲':6,'张三':7,'皮卡丘':8,'王雪':5,}
for i in favorite_num.keys():
print(i+'最喜欢的数字是'+str(favorite_num[i]))
river = {'黄河':'河南','长江':'北京','青海湖':'青海',}
for name,country in river.items():
print(name+'流经的城市包括:'+country)
in_name = ['王菲','张三','皮卡丘','王雪','马辉','刘壮']
for name in in_name:
if name in favorite_num.keys():
print(name+'感谢您参与调查。')
else:
print(name+'希望您参与调查。')
#字典的嵌套(列表中嵌套字典,字典中嵌套列表,字典中嵌套字典)
alien_0={'color':'yellow','point':5}
alien_1={'color':'green','point':10}
alien_2={'color':'red','point':15}
aliens = [alien_0,alien_1,alien_2]
for alien in aliens:
for key in alien.keys():
if key == 'color':
print('这个外星人的颜色是:'+alien[key],end="")
else:
print(',分数是:'+str(alien[key]))
#print('这个外星人的颜色是:'+alien[color]+',分数是:'+str(alien[point]))
#print(alien)
pizza = {'crust':'thick','toppings':['mushroom','extra cheese']}
print('You ordered a '+pizza['crust']+'-crust pizza '+'with the following toppings:')
for topping in pizza['toppings']:
print('\t'+topping)
#第六章的练习题2
favorite_places = {
'Mike':['beijing','lanzhou','chongqing'],
'Nike':['changsha'],
'Yuan':['shanghai','feizhou']
}
for name in favorite_places.keys():
print(name+'喜欢的城市:',end='')
for place in favorite_places[name]:
print('\t'+place.title(),end='')
print('\n')
cities = {
'Shanghai':{'country':'Shanghai','population':52,'fact':'middle'},
'Beijing':{'country':'Beijing','population':70,'fact':'middle'},
'Henan':{'country':'Zhengzhou','population':88,'fact':'big'},
}
for city,city_info in cities.items():
print('\n城市的名称是:'+city+',',end='')
for key in city_info.keys():
#print(key)
if key == 'country':
print('它的省会是:'+city_info[key]+',',end='')
if key == 'population':
print('人口有:'+str(city_info[key])+'亿,',end='')
if key == 'fact':
print('它的规模是:'+city_info[key]+'.')
##大家好,今天是2018年12月21日,晚上来的时候下雪啦,我是皮卡丘,这是我看Python编程从入门到实践的第二天,现在是晚上,我敲的是第七章的内容
#第七章练习题1
pizza = ''
while pizza != 'quit':
pizza = input('1.请输入披萨的配料:')
print(pizza)
active = True
while(active):
pizza = input('2.请输入披萨的配料:')
if pizza != 'quit':
print(pizza)
else:
active=False
while(True):
message = '请输入观众的年龄:'
age = input(message)
if age == 'quit':
break;
else:
age = int(age)
if age < 3:
ticket = 0
elif age < 12 and age >=3:
ticket = 10
else:
ticket = 15
print(ticket)
pets = ['cat','dog','cat','cat','changjinglu','lion','pig','spider']
print(pets)
#pets.remove('cat')//list的remove方法仅移除第一个,不移除重复的
#print(pets)
while 'cat' in pets:
pets.remove('cat')
print(pets)
response = {}
active = True
while(active):
name = input('请输入你的名字:')
answer = input('请输入你的回答:')
response[name] = answer
again = input('是否继续?yes|no')
if again.lower() == 'no':
active = False
print('\n-----总共有如下问卷-------')
for name,answer in response.items():
print('名字是:'+name+',您的回答是:'+answer)
sandwich_orders = ['a','b','c','d','e','f']
finished_orders = []
while sandwich_orders:
out = sandwich_orders.pop()
print('I made your tuna sandwich:'+out)
finished_orders.append(out)
print('\n---------Finished Sandwiches-------------')
for order in finished_orders:
print(order,end=' ')
print('-------欢迎参加我们的问卷调查:如果可以去旅游,您想要去哪里?-------')
travel = {}
active=True
while(active):
name = input('请填写您的名字(如果您不想参加,输入quit即可退出)')
if name == 'quit':
print('继续下一个人的调查')
continue
else:
city = input('请填写您想去的城市')
travel[name] = city
again = input('是否还有人想要参加?Yes|No')
if again.lower() == 'no':
break
print('\n------------如下是我们调查问卷的结果-------------')
for name,city in travel.items():
print(name.title()+'最想去的地方是'+city.title())