Python程序设计与算法基础教程(第二版)微课版第五章上机实践答案
2.
str = input("请输入字符串:")
count=0
for i in str.split(' '):
count += 1
print(count)
3.
a = [1,5,2,53,32,6,3,2,1,6]
b = []
for i in a :
if i not in b :
b.append(i)
print(b)
4.
s=[9,7,8,3,2,1,55,6]
num = len(s)
Max = max(s)
Min = min(s)
Sum = sum(s)
Ave = sum(s) / len(s)
max = s[0]
min = s[0]
sum = 0
num = 0
for i in s:
num += 1
sum += i
if(i > max) : max = i
if(i < min) : min = i
ave = sum / num
max = s[0]
min = s[0]
sum = 0
num = 0
for i in range(0,len(s)) :
if(s[i]>max) :max = s[i]
if(s[i] < min) : min = s[i]
num+=1
sum+=s[i]
ave = sum / num
max = s[0]
min = s[0]
sum = 0
num = 0
i = 0
while i < len(S):
if(s[i]>max) :max = s[i]
if(s[i] < min) : min = s[i]
i +=1
sum+=s[i]
ave = sum / i
max = s[0]
min = s[0]
sum = 0
num = len(s)
i = num-1
while(i >= 0) :
sum += s[i]
if(s[i]>max) :max = s[i]
if(s[i] < min) : min = s[i]
i -= 1
ave = sum / num
max = s[0]
min = s[0]
sum = 0
num = len(s)
i = 0
while(True) :
if(i > num-1) : break
sum += s[i]
if(s[i]>max) :max = s[i]
if(s[i] < min) : min = s[i]
i += 1
5.
s = [9,7,8,3,2,1,5,6]
for i in range(0, len(s)) :
if (s[i] % 2 == 0) :
s[i] = s[i] ** 2
print(s)
6.
s = input("请输入一个字符串:")
l = list()
for i in s :
l.append(ord(i))
print(l)
满怀希望就会所向披靡