본문 바로가기

스파르타코딩개발일지

TIL17일차

이제 파이썬 기초문법+심화과정을마치고

Django과정을 시작했다.

 

배우고 느낀점은 Java -Spring 보다 훨씬 쉽고 직관적이며 다양한기능들이 있다는걸 알수있엇다.

맨처음부터 파이썬을 배웠으면 어땟을까 라는 생각이들기도한다.

 

 

다음은

타임어택 첫 수업을했다

총 네문제

 

1번문제

a = 10

def test1():
    b = 20

def test2():
    print(a)
    print(b)

test1()
test2()
# 실행이 잘 될까요?
# 실행이 되지 않는다면 어떤 에러가 발생할까요?
#8번줄에서 에러가갑니다
#a는 전역변수이고 b는 test1함수에서만 사용할수있는 지역변수이기때문에
#test2에서는 a변수만 사용이가능하고 b함수는 사용이 불가능합니다.
 
 
쉬움
# mutable
a={1,2,3,4,5,6,}
b=['asd','sdf','fgd','gew4465']
c={'age ':19,'gender ': 'man'}
print(type(a)) # set
print(type(b)) #list
print(type(c)) #dict
# immutable
a=10
b=10.56
print(type(a)) # int
print(type(b))  #float
 
2번문자 mutable 과 immutable 의종류
 
쉬움

3번문제

def get_even_numbers(numbers):
    result = [ x for x in numbers if x%2==0]
    return result
 
def get_some_numbers(numbers):
    result = []
    result = list(filter(lambda x: x%3 ==0 and x%15 !=0,numbers))
    result =list(map(lambda x: x*10,result))
    return result

def main():
    numbers = [x for x in range(1,1001)] # 1 ~ 10000

   
    even_numbers = get_even_numbers(numbers)
    some_numbers = get_some_numbers(numbers)
    print(even_numbers) # [2, 4, 6, ...]
    print(some_numbers) # [30, 60, 90, 120, 180, ...]
   
main()

각각의 함수에 알맞는 공식 적기

짝수구하는 방법은 쉬웠고

 

(3의배수 +15의배수아닌수) x10 출력하기

순서가 다르긴했지만 답은 맞았다.

 

4번문제

from pprint import pprint

users = [
    {"name": "Ronald", "age": 30, "math_score": 93, "science_score": 65, "english_score": 93, "social_score": 92},
    {"name": "Amelia", "age": 24, "math_score": 88, "science_score": 52, "english_score": 78, "social_score": 91},
    {"name": "Nathaniel", "age": 28, "math_score": 48, "science_score": 40, "english_score": 49, "social_score": 91},
    {"name": "Sally", "age": 29, "math_score": 100, "science_score": 69, "english_score": 67, "social_score": 82},
    {"name": "Alexander", "age": 30, "math_score": 69, "science_score": 52, "english_score": 98, "social_score": 44},
    {"name": "Madge", "age": 22, "math_score": 52, "science_score": 63, "english_score": 54, "social_score": 47},
    {"name": "Trevor", "age": 23, "math_score": 89, "science_score": 88, "english_score": 69, "social_score": 93},
    {"name": "Andre", "age": 23, "math_score": 50, "science_score": 56, "english_score": 99, "social_score": 54},
    {"name": "Rodney", "age": 16, "math_score": 66, "science_score": 55, "english_score": 58, "social_score": 43},
    {"name": "Raymond", "age": 26, "math_score": 49, "science_score": 55, "english_score": 95, "social_score": 82},
    {"name": "Scott", "age": 15, "math_score": 85, "science_score": 92, "english_score": 56, "social_score": 85},
    {"name": "Jeanette", "age": 28, "math_score": 48, "science_score": 65, "english_score": 77, "social_score": 94},
    {"name": "Sallie", "age": 25, "math_score": 42, "science_score": 72, "english_score": 95, "social_score": 44},
    {"name": "Richard", "age": 21, "math_score": 71, "science_score": 95, "english_score": 61, "social_score": 59},
    {"name": "Callie", "age": 15, "math_score": 98, "science_score": 50, "english_score": 100, "social_score": 74},
]
# print(users[0])
users.sort(key=lambda x:sum([x["math_score"],x['science_score'],x['social_score'],x['english_score']]),reverse=True)

# 나이순으로 정렬 역순은 ,reverse=True
pprint(users, width=300, sort_dicts=False)
# """
# [{'name': 'Ronald', 'age': 30, 'math_score': 93, 'science_score': 65, 'english_score': 93, 'social_score': 92},
#  {'name': 'Trevor', 'age': 23, 'math_score': 89, 'science_score': 88, 'english_score': 69, 'social_score': 93},
#  {'name': 'Callie', 'age': 15, 'math_score': 98, 'science_score': 50, 'english_score': 100, 'social_score': 74},
#  {'name': 'Sally', 'age': 29, 'math_score': 100, 'science_score': 69, 'english_score': 67, 'social_score': 82},
#  {'name': 'Scott', 'age': 15, 'math_score': 85, 'science_score': 92, 'english_score': 56, 'social_score': 85},
#  {'name': 'Amelia', 'age': 24, 'math_score': 88, 'science_score': 52, 'english_score': 78, 'social_score': 91},
#  {'name': 'Richard', 'age': 21, 'math_score': 71, 'science_score': 95, 'english_score': 61, 'social_score': 59},
#  {'name': 'Jeanette', 'age': 28, 'math_score': 48, 'science_score': 65, 'english_score': 77, 'social_score': 94},
#  {'name': 'Raymond', 'age': 26, 'math_score': 49, 'science_score': 55, 'english_score': 95, 'social_score': 82},
#  {'name': 'Alexander', 'age': 30, 'math_score': 69, 'science_score': 52, 'english_score': 98, 'social_score': 44},
#  {'name': 'Andre', 'age': 23, 'math_score': 50, 'science_score': 56, 'english_score': 99, 'social_score': 54},
#  {'name': 'Sallie', 'age': 25, 'math_score': 42, 'science_score': 72, 'english_score': 95, 'social_score': 44},
#  {'name': 'Nathaniel', 'age': 28, 'math_score': 48, 'science_score': 40, 'english_score': 49, 'social_score': 91},
#  {'name': 'Rodney', 'age': 16, 'math_score': 66, 'science_score': 55, 'english_score': 58, 'social_score': 43},
#  {'name': 'Madge', 'age': 22, 'math_score': 52, 'science_score': 63, 'english_score': 54, 'social_score': 47}]
# """
 
 
 
 
예전에못풀었던 문제인데 이번기회에 한번더 복습할수 있는 기회였다

'스파르타코딩개발일지' 카테고리의 다른 글

TIL19일차  (0) 2022.09.28
TIL 18일차  (0) 2022.09.26
TIL16일차  (0) 2022.09.22
TIL15일차.  (0) 2022.09.21
TIL 14일차.  (0) 2022.09.20