第1章
一、选择题
1.B 2.D 3.C 4.C
二、简答题
1.
(1)简单易学 (2)解释性 (3)可移植性 (4)可扩展性 (5)面向对象 (6)丰富的库
2.
(1)Web应用开发 (2)自动化运维 (3).网络安全 (4).网络爬虫 (5).游戏开发 (6).数据分析 (7).人工智能
三、编程题
1.print('Hello, World!.')
jqery下载出现脚本错误怎么办
2.print('***********************************')
print('\t\tHello Python World!')
print('***********************************')
第2章
2.6习题
一、选择题
1.C 2.D 3.C 4.A 5.B 6.D
二、填空题
2.26 2.type() 3.27 4. -5.75; -6 5. False
三、简答题
1.
(1)变量名必须由字母、数字、或者下划线(_)组成。
(2)不能使用空格、连字符、标点符号、引号等其他特殊字符。
(3)以字母或下划线开头,但不能以数字开头
(4)严格区分大小写。
(5)要避免与Python关键字和函数名冲突
2. 见表2.4.
第3章
3.4综合实验
#1
s1 = " keep on going never give up "
s2 = s1.capitalize()
print(s2)
#2
s3 = s2.strip()
print(s3)
#3
print (s3.endswith('up'))
#4
print (s3.startswith('on'))
#5
print (s3.replace('e','aa'))
#6
print (s3.split('n'))
#7
print (s3.upper())
#8
n1 = 'Lily'
print ('%s says: %s.'%(n1,s3))
#9
print (s3.center(40,'#'))
#10
print (s3.count('e'))
#11
print (s3.split())
#12
print ('/'.join(s4))
#13
print (' '.join(s4[::-1]))
3.5 习题
一、选择题
1.B 2.D 3.C 4.C
二、填空题
1. 'moon'
2. 'shipfriend'
3. 5
4. 'bEIjING'民科微服务入口
5. spam
三、编程题
1.
str1 = 'I want to go to Beijing, Berli and Beijing this year. How about you?'
str2 = str1.split()
str2 = ' '.join(str2)
print (str2)
2.
思路:
(1).变量名的第一个字符是否为字母或下划线
(2).如果是,继续判断 --> 4
(3).如果不是,报错
(4).依次判断除了第一个字符之外的其他字符
(5).判断是否为字母数字或者下划线
while True:
s = input('请输入字符(q退出):')
if s == 'q':
exit()
#判断字符串第一个变量是否满足条件
android系统的缺点 if s[0].isalpha() or s[0] == '_':
for i in s[1:]:
#判断判断除了第一个元素之外的其他元素是否满足条件
if i.isalnum() or i == '_':
continue
else:
print('不合法')
break
else:
sql获取当前日期 print('合法')
else:
print('不合法')
3.
#!/usr/bin/env python
#coding:utf-8
s = input("输入:")
s1 = s.split(" ")
s2 = s1[0].upper()
s3 = s1[-1].upper()
print (s2.count(s3))
4.
s = input('input a string:\n')
letters, space, digit, others = 0,0,0,0
for c in s:
if c.isalpha():
letters += 1
elif c.isspace():
space += 1
elif c.isdigit():
digit += 1
else:
others += 1
print ('char = %d,space = %d,digit = %d,others = %d' % (letters,space,digit,others))
第4章
4.4 综合实验
#01
fav_city = []
#02
fav_city.append('Qinghai')
fav_city.append('Chengdu')
fav_city.append('Dalian')
fav_city.append('Xizang')
fav_city.append('Haerbin')
print (fav_city)
#03
fav_city[0] = 'Qingdao'
#04
fav_city.insert(2,'Kunming')
#05
del fav_city[0]
#06
ve('Xizang')
#07
fav_city.sort()
#08
verse()
#09
for city1 in fav_city:
print (city1)
#10
tuple_city = tuple(fav_city)
#11excel截取中间字符串函数
len(tuple_city)
4.5 习题
一、选择题
1.D 2.A 3.B 4.D 5.C
二、填空题
1.[123,22, 123,22]
2.x = [1,3,5,7,9]
3. [11,22,33,11]
4. Flase
5. b= [::2]
6. (6,)
三、编程题
#1
import random
x = [random.randint(0,100) for i in range(10)]
x.sort()
print (x)
#2.
list1 = ['Hollywood', 'Mexico', 'New Delhi', 'Tokyo']
item = list1.pop(0)
list1.append(item)
print (list1)
#3
a = int(input('a:'))
for b in x:
if a < b:
x.insert(x.index(b),a)
break
else:
x.append(a)
print (x)
#3
x.pop()
x[:5] = sorted(x[:5] ,reverse = True)
x[5:] = sorted(x[5:])
print (x)
4.
#列表推导法
list1 = [22,11,33,22,44,33]
temp_list=[]
for x in list1:
if x not in temp_list:
temp_list.append(x)
print (temp_list) #输出结果未排序
#排序方法
list1 = [22,11,33,22,44,33]
list2 = sorted(list1)
temp_list = []
i = 0
while i < len(list2):
python数据分析基础教程答案 if list2[i] not in temp_list:
temp_list.append(list2[i])
else:
i += 1
print (temp_list) #输出结果已排序
第5章 字典
综合实验
1.
Qing_Hai = ['qinghai','xining','青',8,'810000']
Si_Chuan = ['sichuan','chengdu','川',21,'610000']
Gan_Su = ['gansu','lanzhou','陇',14,'730000']
Ning_Xia = ['ningxia','yinchuan','宁',5,'750000']
Nei_MengGu = ['neimenggu','huhehaote','内蒙古',12,'010000']
Shaan_Xi = ['shaanxi','xian','陕',10,'710000']
Shan_Xi = ['shanxi','taiyuan','晋',11,'030000']
He_Nan = ['henan','zhengzhou','豫',18,'450000']
Shan_Dong = ['shandong','jinan','鲁',16,'250000']
provinces = [Qing_Hai,Si_Chuan,Gan_Su,Ning_Xia,Nei_MengGu,Shaan_Xi,Shan_Xi,He_Nan,Shan_Dong]
Yellow_River_basin = {}
for province in provinces:
Yellow_River_basin[province[0]] = province[1:]
print(Yellow_River_basin)
2.
# 遍历嵌套字典的键
for key in Yellow_River_basin.keys():
print(key)
# 遍历嵌套字典的值
for value in Yellow_River_basin.values():
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论