Day_06_Homework_Answer
for i in range(1,101):
if i % 7 == 0:
print(i, end=' ')
print()
for i in range(1, 101):
if i % 2 == 1:
print(i, end=' ')
print()
s = 0
for i in range(1, 101):
if i % 2 == 0:
s += i
print(i)
n = int(input('n(大于1的数):'))
for i in range(2, n):
if n % i == 0:
print('是合数')
break
else:
print('不是合数')
n = int(input('n(大于1的数):'))
for i in range(2, 999999):
if n % i == 0 and n != i:
print('不是素数')
break
else:
print('是素数')
s = 0
for i in range(1, 101):
if i == 3 or i % 10 == 3:
continue
else:
s += i
print(s)
s = 2000
for i in range(1, 21):
s += s * 0.05
print(s)
g = 50
s = 15
a = 50 - 15
count = 0
for i in range(1, 100):
a -= 5
count += 1
if a == 0:
break
print(count)
'''
正确示范:
count = 0
for i in range(15, 50, 5)
count +=1
print(count)
'''
for i in range(100, 201):
if i % 3 == 0 or i % 7 == 0:
print(i, end=' ')
print()
n = 1
for i in range(1, 11):
n *= i
print(n)
'''
正确示范:
n = 1
s = 0
for i in range(1, n+1):
s *= i
print(s)
'''
s = 0
for i in range(1, 100):
s += i
print(s)
'''
正确示范:
s = 0
for i in range(1, 100, 2):
s += i
print(s)
'''
count = 0
for i in range(20, 81):
if i % 3 == 0:
print(i, end=' ')
count += 1
if count % 5 == 0:
print()
count = 0
for i in range(1000, 2001):
if i % 4 == 0 and i % 100 != 0 or i % 400 == 0:
print(i, end=' ')
count += 1
if count % 4 == 0:
print()
s = 0
for i in range(1, 101):
if i % 2 == 0:
s -= 1 / i
if i % 2 == 1:
s += 1 / i
print(s)
n = 1
for i in range(1, 10):
for j in range(1, i+1):
print(j, "*", i, "=", j*i, end=' ')
print()
'''
1 * 1 = 1
1 * 2 = 2 2 * 2 = 4
1 * 3 = 3 2 * 3 = 6 3 * 3 = 9
1 * 4 = 4 2 * 4 = 8 3 * 4 = 12 4 * 4 = 16
1 * 5 = 5 2 * 5 = 10 3 * 5 = 15 4 * 5 = 20 5 * 5 = 25
1 * 6 = 6 2 * 6 = 12 3 * 6 = 18 4 * 6 = 24 5 * 6 = 30 6 * 6 = 36
1 * 7 = 7 2 * 7 = 14 3 * 7 = 21 4 * 7 = 28 5 * 7 = 35 6 * 7 = 42 7 * 7 = 49
1 * 8 = 8 2 * 8 = 16 3 * 8 = 24 4 * 8 = 32 5 * 8 = 40 6 * 8 = 48 7 * 8 = 56 8 * 8 = 64
1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81
'''
a = {"name": "John", "age": 19, "score": 100, "number": 18565611037, "sex": "男"}
b = {"name": "Joker", "age": 18, "score": 91, "number": 32131568, "sex": "男"}
c = {"name": "Barry", "age": 18, "score": 92, "number": 321578768, "sex": "男"}
d = {"name": "Tony", "age": 19, "score": 75, "number": 123498098543, "sex": "不明"}
e = {"name": "Mary", "age": 19, "score": 42, "number": 178987654, "sex": "女"}
f = {"name": "eric", "age": 19, "score": 58, "number": 234768654321, "sex": "男"}
list1 = [a, b, c, d, e, f]
count = 0
for k in list1:
if k["score"] < 60:
count += 1
print(count)
for k in list1:
if k["score"] < 60:
print(k['name'], k['score'])
count = 0
for k in list1:
if k["age"] < 18:
count += 1
print(count)
for k in list1:
if k["number"] % 10 == 8:
print(k['name'])
max_score = 0
max_name = ''
for k in list1:
if(k['score']) > max_score:
max_score = k['score']
max_name = k['name']
print(max_name, max_score)
i = 0
while i < len(list1):
k = list1[i]
if k['sex'] == '不明':
list1.pop(i)
i -= 1
i += 1
print(list1)
for i in range(len(list1)-1):
for j in range(len(list1)-1-i):
if list1[j]['score'] < list[j + 1]['score']:
list1[j], list1[j + 1] = list1[j + 1], list1[j]
print(list1)
list1.sort(key=lambda k:k['score'])
print(list1)