[Pythonベース]Day_06_作業参考回答


Day_06_Homework_Answer
# for    

#   

# 1,  100  7   
for i in range(1,101):
    if i % 7 == 0:
        print(i, end=' ')
print()

# 2,  100     
for i in range(1, 101):
    if i % 2 == 1:
        print(i, end=' ')
print()

# 3,  100        
s = 0
for i in range(1, 101):
    if i % 2 == 0:
       s += i
print(i)

# 4,          。(         1      ,         (   0)  。)
n = int(input('n(  1  ):'))
for i in range(2, n):  #     n,   2for     
    if n % i == 0:
        print('   ')
        break
else:
    print('    ')

# 5,          。(  1                。)
n = int(input('n(  1  ):'))
for i in range(2, 999999):
    if n % i == 0 and n != i:
        print('    ')
        break
else:
    print('   ')

# 6,   1~100    ,          3  。
s = 0
for i in range(1, 101):
    if i == 3 or i % 10 == 3:
        continue
    else:
        s += i
print(s)

# 7,      ,    2000    ,       5%,20         ?
s = 2000
for i in range(1, 21):
    s += s * 0.05
# s = s * (1+0.1)**10

print(s)

# 8,          50  ,   15  。           ,     5 。
#     :                 ?          。
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)
'''

# 9,   100–200      3  7    
for i in range(100, 201):
    if i % 3 == 0 or i % 7 == 0:
        print(i, end=' ')
print()

# 10,   10   (1*2*3*4*5*6*7*8*9*10, n   :1*2……*n)
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)
'''

# 11,   1+3+5+...+99  
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)
'''

# 12,   20~80    3     ,   5 
count = 0
for i in range(20, 81):
    if i % 3 == 0:
        print(i, end=' ')
        count += 1
    if count % 5 == 0:
        print()

# 13,   1000~2000       ,   4 
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()

# 14,  : 1- 1/2 + 1/3 - 1/4 …  1/100  
#     : 1/1-1/2+1/3-1/4 …  1/100
s = 0
for i in range(1, 101):
    if i % 2 == 0:
        s -= 1 / i
    if i % 2 == 1:
        s += 1 / i
print(s)

# 15,   99   
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
'''


#    

# 1.                ,       :
#         、  、  (  )、  、  ( 、 、  )

# 2.       ,      6      (6 ( 1)    )

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]

#   (1)           
count = 0
for k in list1:
    if k["score"] < 60:
        count += 1
print(count)

#   (2)                 
for k in list1:
    if k["score"] < 60:
        print(k['name'], k['score'])

#   (3)           
count = 0
for k in list1:
    if k["age"] < 18:
        count += 1
print(count)

#   (4)        8      

for k in list1:
    if k["number"] % 10 == 8:
        print(k['name'])

#   (5)               
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)

#   (6)            (  )
i = 0
while i < len(list1):
    k = list1[i]
    if k['sex'] == '  ':
        list1.pop(i)
        i -= 1
    i += 1
print(list1)

#   (7)               ( )

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)