浙大版《Python程序设计》题目集(第五章)
num = eval(input())
abbr = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]
print(abbr[num - 1])
num = eval(input())
count = 1
ls = []
vertex = []
len_sum = 0
vertex_sum = 0
edge = 0
while count <= num:
strs = input()
ls.append(strs)
count = count + 1
for str in ls:
for t in range(len(str)):
if str[t].isdigit():
if str[t + 1].isdigit():
s = str[t] + str[t + 1]
len_sum = len_sum + int(s)
edge = edge + 1
continue
else:
len_sum = len_sum + int(str[t])
if not str[t - 1].isdigit():
edge = edge + 1
continue
else:
continue
elif str[t].isalpha() and str[t] not in vertex:
vertex.append(str[t])
continue
else:
continue
vertex_sum = vertex_sum + len(vertex)
print(vertex_sum,edge,len_sum,sep = ' ',end = '')
num1 = eval(input())
operation = input()
num2 = eval(input())
dict = {"+":format(num1 + num2,'.2f'),"-":format(num1 - num2,'.2f'),"*":format(num1 * num2,'.2f'),"/":format(num1 / num2,'.2f') if num2 != 0 else "divided by zero"}
for key in dict.keys():
if key == operation:
print(dict[key])
scores = set(map(int,input().split(",")))
for i in range(6,11):
if i not in scores:
print(i)
else:
continue
strs = input()
look = input()
count = 0
for str in strs:
if look == str:
count = count + 1
print(count)
num = eval(input())
ages = list(map(int,input().split(" ")))
dict = {}
for age in ages:
count = 0
if age not in dict.keys():
count = 1
dict.update({age:count})
continue
else:
count = dict[age] + 1
dict.update({age:count})
continue
ls = zip(dict.keys(),dict.values())
ages = sorted(ls,key = lambda ls:ls[0])
for age in ages:
print(age[0],":",age[1],sep = '')
strs = input()
ls = strs[1:-1].split(",")
ls_single = list(set(ls))
ls_single.sort(key = ls.index)
for t in ls_single:
print(int(t),end = ' ')
#题目要求方法
a,b = map(int,input().split(" "))
ls = []
for i in range(a,b + 1):
if i % (3 * 5 * 7) == 0:
ls.append(i)
res = set(ls)
print(len(res))
#常规方法
a,b = map(int,input().split(" "))
ls = []
for i in range(a,b + 1):
if i % 3 == 0 and i % 5 == 0 and i % 7 == 0:
ls.append(i)
print(len(ls))
import numpy as np
dimension = eval(input())
count = 1
matrix = []
cnt = 0
while count <= dimension:
rows = list(map(int,input().split(" ")))
matrix.append(rows)
count = count + 1
for row in range(len(matrix)):
row_max = max(matrix[row])
for col in range(len(matrix[row])):
if matrix[row][col] == row_max:
col_min = min(np.array(matrix)[:,col])
if col_min == matrix[row][col]:
cnt = cnt + 1
else:
break
print(cnt)
#方法一(常规)
nums = list(map(int,input().split(",")))
num = eval(input())
dict = {}
count = 0
for i in range(len(nums)):
for j in range(i + 1,len(nums)):
if nums[i] + nums[j] == num:
dict.update({i:j})
count = count + 1
else:
continue
if not count:
print("no answer")
else:
for key,value in dict.items():
print(key,value)
#方法二(一重循环+字典实现)
nums = list(map(int,input().split((","))))
num = eval(input())
i = 0
j = 1
dict = {}
count = 0
while i < len(nums) and j < len(nums):
if nums[i] + nums [j] == num:
dict.update({i:j})
count = count + 1
break
else:
j = j + 1
if j == len(nums):
j = 0
i = i + 1
else:
continue
if not count:
print("no answer")
else:
for key,value in dict.items():
print(key,value)
str1 = eval(input())
str2 = eval(input())
dict = {}
values = {}
for key,value in str1.items():
if key not in dict.keys():
dict[key] = value
values[key] = value
for key,value in str2.items():
if key not in dict.keys():
dict[key] = value
else:
dict[key] = value + values[key]
ls = sorted(dict.items(),key = lambda dict:dict[0] if type(dict[0]) == int else ord(dict[0]))
print("{",end = '')
for t in ls:
if type(t[0]) == int:
print('{}:{}'.format(*t),end = '')
elif type(t[0]) == str:
print('"{}":{}'.format(*t),end = '')
if t != ls[-1]:
print(",",end = '')
print("}")
本文来自博客园,作者:闲晚,转载请注明原文链接:https://www.cnblogs.com/centimeter73/p/15472859.html
浙公网安备 33010602011771号