浙大版《Python程序设计》题目集(第三章)
height = list(map(int,input().split(" ")))
sum = 0
for i in height:
sum = sum + i
avg = sum / len(height)
for i in height:
if i > avg:
print(i,end = " ")
num = eval(input())
i = 1
ls = []
count = 0
weight = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]
M = ['1','0','X','9','8','7','6','5','4','3','2']
add_weight = 0
error = []
while i <= num:
str = input()
ls.append(str)
i = i + 1
for k in range(len(ls)):
if ls[k][:-1].isdigit():
for t in range(len(ls[k]) - 1):
add_weight = add_weight + int(ls[k][t])*weight[t]
res = add_weight % 11
if M[res] == ls[k][-1]:
continue
else:
error.append(ls[k])
else:
error.append(ls[k])
count = count + 1
if count:
for m in error:
print(m)
else:
print("All passed")
str = input()
a,b = input().split(" ")
index_list = []
char_list = []
for i in range(len(str)):
if str[i] == a or str[i] == b:
char_list.append(str[i])
index_list.append(i)
list = list(zip(index_list[::-1],char_list[::-1]))
for j in range(len(list)):
print(list[j][0],list[j][1])
look = input()
str = input()
index = 0
flag = False
for i in range(len(str)):
if str[i] == look:
index = i
flag = True
if not flag:
print("Not Found")
else:
print("index = ",index,sep = "")
str = input()
res = ""
for i in range(len(str)):
if str[i] <= '9' and str[i] >= '0':
res = res + str[i]
print(int(res))
values = list(map(int,input().split(" ")))
num = values[0]
dict = {}
for i in values[1::]:
if i in dict.keys():
dict[i] = dict[i] + 1
else:
dict[i] = 1
max_values = max(dict.values())
for key,value in dict.items():
if value == max_values:
print(key,value)
num = eval(input())
count = 1
values = []
dict = {}
values = list(map(int,input().split(" ")))
for i in range(len(values)):
if not (values[i] in dict.keys()):
dict.update({values[i]:i})
max_keys = max(dict.keys())
for key,value in dict.items():
if key == max_keys:
print(key,value)
str = input()
print(str[::-1])
while True:
strs = input()
if strs[-1] == "#":
strs = strs[:-1]
break
ls = []
flag = False
for str in strs:
if str == "-":
flag = True
ls.append(str)
ls_select = []
strs_select = ""
for i in ls:
if (i <= 'f' and i >= 'a') or (i <= 'F' and i >= 'A') or (i <= '9' and i >= '0'):
ls_select.append(i)
for t in ls_select:
strs_select = strs_select + t
if len(strs_select) != 0 and flag == True:
print("-",int(strs_select,16),sep = '')
else:
print(int(strs_select,16))
str = input()
count = 0
for i in str:
if i != 'A' and i != 'E' and i != 'I' and i != 'O' and i != 'U' and i <= 'Z' and i >= 'A':
count = count + 1
print(count)
strs = list(input().split(" "))
#冒泡排序算法实现
import operator
for i in range(len(strs)):
for j in range(i+1,len(strs)):
if operator.lt(strs[j],strs[i]):
t = strs[j]
strs[j] = strs[i]
strs[i] = t
print("After sorted:")
for str in strs:
print(str)
num = input()
sum = 0
len = len(num)
for i in num:
sum = sum + int(i)
print(len,sum,sep = ' ')
strs = input()
ls = []
for str in strs:
ls.append(str)
for i in range(len(ls)):
if ls[i] >= 'A' and ls[i] <='Z':
ls[i] = chr(155-ord(ls[i]))
for k in ls:
print(k,end = '')
while True:
strs = input()
if strs[-1] == "#":
strs = strs[:-1]
break
ls = []
for str in strs:
ls.append(str)
for i in range(len(ls)):
if ls[i] >= 'a' and ls[i] <= 'z':
ls[i] = ls[i].upper()
elif ls[i] >= 'A' and ls[i] <= 'Z':
ls[i] = ls[i].lower()
for k in ls:
print(k,end = '')
strs = input()
count = 1
i = 0
while i < len(strs):
if strs[i] != ' ':
i = i + 1
else:
if strs[i - 1] != ' ' and i != 0:
count = count + 1
i = i + 1
else:
i = i + 1
print(count)
strs = input()
ls = []
ls_del = []
for str in strs:
ls.append(str)
for i in range(len(ls)):
if ls[i] not in ls_del:
ls_del.append(ls[i])
ls_sort = sorted(ls_del,reverse = False)
for i in ls_sort:
print(i,end = '')
strs = input().strip()
ch = input().strip()
ls = []
i = 0
for str in strs:
ls.append(str)
length = len(ls)
while i < length:
if (ord(ls[i]) == ord(ch)) or ((ord(ls[i]) + 32) == ord(ch)) or ((ord(ls[i]) - 32) == ord(ch)):
ls.pop(i)
length = length - 1
else:
i = i + 1
res = ""
for k in ls:
res = res + k
print("result:",res)
strs = input()
ls = []
dict = {}
count = 0
num = 0
for str in strs:
ls.append(str)
for i in ls:
if dict:
if i <= 'z' and i >= 'a':
for j in list(dict.keys()):
if ord(i) != ord(j) + 32 and ord(i) != ord(j):
num = num + 1
if num == len(list(dict.keys())):
dict.update({i:"true"})
count = count + 1
num = 0
else:
num = 0
break
elif i <= 'Z' and i >= 'A':
for j in list(dict.keys()):
if ord(i) != ord(j) and ord(i) != ord(j) -32:
num = num + 1
if num == len(list(dict.keys())):
dict.update({i:"true"})
count = count + 1
num = 0
else:
num = 0
break
else:
dict.update({i:"true"})
count = count + 1
if count < 10:
print("not found")
else:
for key in dict.keys():
print(key,end = '')
num = eval(input())
count = 1
ls = []
while count <= num:
str = input()
ls.append(str)
count = count + 1
max_len = len(ls[0])
for i in ls:
if len(i) > max_len:
max_len = len(i)
max = i
print("The longest is",max)
strs = input()
ls = []
i = 0
for str in strs:
ls.append(str)
while i < len(ls):
if int(ls[-1]) != 0:
for j in ls[::-1]:
print(j,end = '')
i = len(ls)
else:
if int(ls[-2]) == 0:
print(ls[0])
break
else:
print(ls[1],ls[0],sep = '')
break
strs = input()
ls = []
count = 1
for str in strs:
ls.append(str)
for i in range(len(ls) // 2):
if ls[i] == ls[len(ls) - 1 -i]:
count = count + 1
if count > len(ls) // 2:
print("Yes")
else:
print("No")
strs = input()
ls = []
dict = {}
for str in strs:
ls.append(str)
for i in range(len(ls)):
if ls[i] <= 'Z' and ls[i] >= 'A' and i != 0:
if not ls[i] in dict.keys():
dict.update({ls[i]:"true"})
else:
continue
elif ls[i] <= 'Z' and ls[i] >= 'A' and i == 0:
dict.update({ls[i]:"true"})
else:
continue
if not len(dict):
print("Not Found")
else:
for key in dict.keys():
print(key,end = '')
本文来自博客园,作者:闲晚,转载请注明原文链接:https://www.cnblogs.com/centimeter73/p/15463543.html