首页 > 编程语言 > 详细

《python核心编程第二版》第2章习题

时间:2019-03-24 22:35:38      阅读:151      评论:0      收藏:0      [点我收藏+]

2-1 略

2-1 略

2-2

(a)打印 结果是9

(b)9

(c)一样

(d)略

(e)略

2-3 略

2-4 (a)

# /usr/bin/python
raw_input()

(b)

# /usr/bin/python
str1 = raw_input()
print int(str1)

2-5

 (a)

# /usr/bin/python
i=1
while i < 11:
print i
i = i+1

 (b)

# /usr/bin/python
for i in range(1,11):
print i

2-6

# /usr/bin/python
# coding:utf8
num = raw_input()
if num >0:
print "正数"
elif num <0:
print "负数"
else:
print "0"

2-7

# /usr/bin/python
# coding:utf8
flag = 1

while flag != ‘0‘:
flag = raw_input()
print flag

2-8

# /usr/bin/python
# coding:utf8
list1 = [1,2,9,3,4]
print sum(list1)

for i in range(0,5):
list1[i] = int(raw_input())
print sum(list1)

2-9

# /usr/bin/python
# coding:utf8
list1 = [1,2,9,3,4]
print float(sum(list1))/5

2-10

# /usr/bin/python
# coding:utf8
flag =1
while flag!=0:
i = int(raw_input())
if i>1 and i <100:
flag = 0
else:
print "重新输入"

 

2-11

# /usr/bin/python
# coding:utf8
i = ‘1‘
while i!=‘X‘:
list1 = [1,3,4,5,7]
i = raw_input()
if i == ‘1‘:
print sum(list1)
elif i == ‘2‘:
print float(sum(list1))/5

2-12

(a)[‘__builtins__‘, ‘__doc__‘, ‘__file__‘, ‘__name__‘, ‘__package__‘]

(b)<built-in function dir>

(c)报错

(d)略

2-13

(a)[‘__displayhook__‘, ‘__doc__‘, ‘__egginsert‘, ‘__excepthook__‘, ‘__name__‘, ‘__package__‘, ‘__plen‘, ‘__stderr__‘, ‘__stdin__‘, ‘__stdout__‘, ‘_clear_type_cache‘, ‘_current_frames‘, ‘_getframe‘, ‘_mercurial‘, ‘api_version‘, ‘argv‘, ‘builtin_module_names‘, ‘byteorder‘, ‘call_tracing‘, ‘callstats‘, ‘copyright‘, ‘displayhook‘, ‘dont_write_bytecode‘, ‘exc_clear‘, ‘exc_info‘, ‘exc_type‘, ‘excepthook‘, ‘exec_prefix‘, ‘executable‘, ‘exit‘, ‘flags‘, ‘float_info‘, ‘float_repr_style‘, ‘getcheckinterval‘, ‘getdefaultencoding‘, ‘getdlopenflags‘, ‘getfilesystemencoding‘, ‘getprofile‘, ‘getrecursionlimit‘, ‘getrefcount‘, ‘getsizeof‘, ‘gettrace‘, ‘hexversion‘, ‘long_info‘, ‘maxint‘, ‘maxsize‘, ‘maxunicode‘, ‘meta_path‘, ‘modules‘, ‘path‘, ‘path_hooks‘, ‘path_importer_cache‘, ‘platform‘, ‘prefix‘, ‘py3kwarning‘, ‘setcheckinterval‘, ‘setdlopenflags‘, ‘setprofile‘, ‘setrecursionlimit‘, ‘settrace‘, ‘stderr‘, ‘stdin‘, ‘stdout‘, ‘subversion‘, ‘version‘, ‘version_info‘, ‘warnoptions‘]

(b)

darwin
2.7.10 (default, Oct 6 2017, 22:29:07)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]

(c)略

2-14

print -2*4 + (3**2)

2-15

# /usr/bin/python
# coding:utf8
a = int(raw_input())
b = int(raw_input())
c = int(raw_input())
list1 = [a,b,c]
print sorted(list1)
print sorted(list1,reverse=True)

2-16

 

《python核心编程第二版》第2章习题

原文:https://www.cnblogs.com/love-maodou/p/10590948.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!