python程序设计陈春晖答案_python程序设计课后编程题(陈春晖)

第一章

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

s="Python语言简单易学"

print(s.encode("utf-8"))1

2

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

A=int(input())

B=int(input())

C=A+B

print(C)1

2

3

4

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

a, b, c = map(int, input().split())

print(b*b-4*a*c)1

2

第二章

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

x=input()

x=float(x)

if x==0:

print('f(%.1f) = %.1f'%(x,x))

else:

print('f(%.1f) = %.1f' %(x,1/x))1

2

3

4

5

6

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

n=input()

x=int(n)

if x<0:

print("Invalid Value!")

if x<=50 and x>0:

y=x*0.53

print("cost = %.2f"%y)

if x>50:

z=50*0.53

x=x-50

y=z+x*0.58

print("cost = %.2f"%y)1

2

3

4

5

6

7

8

9

10

11

12

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

n=int(input())

i=a=0

b=1

while i

if b%2==1:

a=a+b/(2*i+1)

i+=1

else:

a=a-(i+1)/(2*i+1)

i+=1

b+=1

print("{0:.3f}".format(a))1

2

3

4

5

6

7

8

9

10

11

12

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

list = input().split(" ")

olist = []

s = 0

for i in list:

if int(i) > 0:

olist.append(int(i))

for i in olist:

if i % 2 != 0:

s += i

print(s)1

2

3

4

5

6

7

8

9

10

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

a,b=map(int,input().split())

i=su=c=0

while i

c=10**i+c

su=su+a*c

i+=1

print("s = %.f"%su)1

2

3

4

5

6

7

第三章

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

x = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]

y = ['1','0','X','9','8','7','6','5','4','3','2']

n = int(input())

m = 0

for i in range(n):

num = str(input())

if len(num)>18:

print(num)

m = 1

else:

a = num[:17]

c = True

b = 0

for j in range(len(a)):

try:

b+=int(a[j])*x[j]

except:

c = False

print(num)

m = 1

break

if c:

b = b%11

if y[b]!=num[-1]:

print(num)

m = 1

if m==0:

print('All passed')1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

import numpy as np

a = list(map(int, input().strip().split()))

n=len(a)

x=np.mean(a)

for i in range(0,n):

if a[i]>x:

print(a[i],end=" ")1

2

3

4

5

6

7

第四章

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

n = int(input())

p = 1

for i in range ( n-1 , 0 , -1 ):

p = ( p + 1 ) * 2

print(p)1

2

3

4

5

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

m,n=map(int,input().split())

a=[]

for i in range(m):

s=input()

a.append([int(n) for n in s.split()])

for j in range(m):

sum=0

for k in range(n):

sum+=a[j][k]

print(sum)1

2

3

4

5

6

7

8

9

10

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

i1=int(input())

f=input()

i2=int(input())

try:

if f.__eq__('+'):

res=i1+i2

elif f.__eq__('-'):

res=i1-i2

elif f.__eq__('*'):

res=i1*i2

else:

res=i1/i2

except ZeroDivisionError :

print("divided by zero")

else:

print('{:.2f}'.format(res))1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

n=int(input())

monkey=[]

timer=0

count=0

if(n>0 and n<=1000):

for i in range(1,n+1):

monkey.append(i)

while(len(monkey)>1):

timer+=1

count+=1

if(count>len(monkey)):

count=1

if(timer==3):

timer=0

monkey.pop(count-1)

count-=1

print(monkey[0])1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

m,n=map(int,input().split())

flag = 0

for i in range(m,n+1):

c = []

a = []

b = i

while int(b) != 0:

b = b/2

if int(b) ==0:

break

if a == []:

b = int(b)

if i%b == 0:

a.append(b)

continue

else:

break

if b%int(b) == 0:

a.append(int(b))

else:

b = int(b)+1

a.append(b)

if i%int(b) != 0:

break

if i == sum(a):

for j in range(1,i):

if i%j == 0:

if j not in c:

c.append(j)

if set(c).symmetric_difference(set(a)) != set():

continue

flag +=1

print(i,end='')

print(' = {}'.format(a[(len(a)-1)]),end='')

for x in range(len(a)-2,-1,-1):

if x == 0:

print(' + {}'.format(a[x]))

else:

print(' + {}'.format(a[x]),end='')

if flag == 0:

print('None')1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

m,n=map(int,input().split())

count = 0

s=0

for num in range(m,n + 1):

# 素数大于 1

if num > 1:

for i in range(2, num):

if (num % i) == 0:

break

else:

count += 1

s+=num

print(count,s)1

2

3

4

5

6

7

8

9

10

11

12

13

第五章

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

n=list(map(int,input().split(',')))

n=sorted(list(set(range(6,11))-set(n)))

print(" ".join(map(str,n[0:])))1

2

3

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

x=eval(input())

y=[]

for i in range(0,len(x)):

if x[i] not in y:

y.append(x[i])

for j in range(0,len(y)-1):

print('%d'%y[j],end=' ')

print(y[-1])1

2

3

4

5

6

7

8

第六章

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

def fn(x,y):

item = 0

s = 0

for i in range(y):

item = item*10+x

s += item

return s

a,b=input().split()

s=fn(int(a),int(b))

print(s)

exit(0)1

2

3

4

5

6

7

8

9

10

11

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

def prime(p):

list = [f for f in range(1, p + 1) if p % f == 0]

if list == [1,p]:

return True

else:

return False

def PrimeSum(m,n):

sum = 0

for i in range(m,n+1):

if prime(i):

sum = sum + i

return sum1

2

3

4

5

6

7

8

9

10

11

12

13

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

def CountDigit(number,digit ):

count=0

if number<0:

number=-number

while number>0:

i=number%10

if i==digit:

count+=1

number//=10

return count1

2

3

4

5

6

7

8

9

10

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

def fib(n):

if n==0 or n==1:

return 1

else:

return fib(n-1)+fib(n-2)

def PrintFN(m,n):

a=[]

#for i in range(m,n+1):

for j in range(26):

if m<=fib(j)<=n:

a.append(fib(j))

#print(a)

return a1

2

3

4

5

6

7

8

9

10

11

12

13

14

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

def funcos(eps,x ):

sum=0

i=0

count=0

while True:

c=1

for j in range(1,2*i+1):

c=c*j

if ((x**(2*i))/c)

return sum

break

else:

if count%2==0:

sum=sum+(x**(2*i))/c

else:

sum=sum-(x**(2*i))/c

i+=1

count+=11

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

第七章

20191105083344327.png

def read(filename):

f = open(filename,'r', encoding="utf-8")

txt = f.read()

f.close()

print(txt)

return txt

def chang(txt):

newtxt = ''

for char in txt:

if 'a' <= char <= "z":

newtxt += chr(ord(char) - 32)

elif 'A' <= char <= 'Z':

newtxt += chr(ord(char) + 32)

else:

newtxt += char

print(newtxt)

return newtxt

def writefile(filename, txt):

fw = open(filename, 'w')

fw.write(txt)

fw.close()

txt = read("F:\\example.txt")

newtxt = chang(txt)

writefile("F:\\result.txt", newtxt)1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

20191105083415151.png

def count(s):

count_a = count_z = count_o = 0

for i in s:

if (ord(i) >= 97 and ord(i) <= 122) or (ord(i) >= 65 and ord(i) <= 90):

count_a = count_a + 1

elif ord(i) >= 48 and ord(i) <= 57:

count_z = count_z + 1

else:

count_o = count_o + 1

print( "英文字母个数:%d个" % count_a)

print( "数字个数:%d个" % count_z)

print("其他字符个数:%d个" % count_o)

f=open("F:\\letter.txt","r")

data=f.read()

print(data)

count(data)1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

import collections

with open("F:\\freedom.txt","r",encoding="utf-8") as file1:

str1 = file1.read().split(' ')

w=open("F:\\dic.txt","w",encoding="utf-8")

str2=str(collections.Counter(str1))

w.write(str2)

Counter({'the': 14, 'of': 12, 'a': 10, 'be': 10, 'and': 10, 'have': 8, 'dream': 8, 'will': 8, 'that': 7, 'one': 7, 'day': 7, 'with': 5, 'to': 4, 'all': 3, 'down': 3, 'in': 3, 'shall': 3, 'made': 3, 'I': 2, 'nation': 2, 'live': 2, 'its': 2, 'sons': 2, 'former': 2, 'able': 2, 'state': 2, 'sweltering': 2, 'heat': 2, 't': 2, 'by': 2, 'their': 2, 'today.\nI': 2, 'Alabama': 2, 'black': 2, 'boys': 2, 'girls': 2, 'white': 2, 'every': 2, 'places': 2, 'this': 1, 'rise': 1, 'up,': 1, 'up': 1, 'true': 1, 'meaning': 1, 'creed:': 1, '“We': 1, 'hold': 1, 'these': 1, 'truths': 1, 'self-evident;': 1, 'men': 1, 'are': 1, 'created': 1, 'equal.”\nI': 1, 'on': 1, 'red': 1, 'hills': 1, 'Georgia': 1, 'slaves': 1, 'slave-owners': 1, 'sit': 1, 'together': 1, 'at': 1, 'table': 1, 'br': 1, 'otherhood.\nI': 1, 'even': 1, 'Mississippi,': 1, 'th': 1, 'e': 1, 'injustice,': 1, 'oppression,': 1, 'transformed': 1, 'into': 1, 'an': 1, 'oasis': 1, 'freedom': 1, 'justice.\nI': 1, 'my': 1, 'four': 1, 'children': 1, 'where': 1, 'they': 1, 'no': 1, 'judged': 1, 'color': 1, 'if': 1, 'skin': 1, 'but': 1, 'content': 1, 'character.': 1, 'governor': 1, 'having': 1, 'his': 1, 'lips': 1, 'drippin': 1, 'g': 1, 'words': 1, 'interposition': 1, 'nullification,': 1, 'right': 1, 'li': 1, 'ttle': 1, 'join': 1, 'hands': 1, 'little': 1, 'as': 1, 'sisters': 1, 'brothers.\nI': 1, 'valley': 1, 'exalted,': 1, 'hill': 1, 'mountain': 1, 'sh': 1, 'low,': 1, 'rough': 1, 'plain,': 1, 'crooked': 1, 'straight,': 1, 'glory': 1, 'Lord': 1, 'revealed,': 1, 'flesh': 1, 'see': 1, 'i': 1, 'toget': 1})1

2

3

4

5

6

7

8

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTA4MjU4Mg==,size_16,color_FFFFFF,t_70

water = open("F:\\water.txt", "r",encoding="utf-8")

for i in water.readlines():

list1=i.split()

sum = 1.05*(int(list1[13])-int(list1[1]))

print("用户{} = {} 元".format(list1[0],sum))

water.close()1

2

3

4

5

6

  • 4
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值