Python(11)
-
Python programmers 자연수 뒤집어 배열로 만들기
자연수 뒤집어 배열로 만들기 def solution(n): arr = list(str(n)) arr.reverse() return list(map(int,arr))
2023.08.25 -
Python str, fstr
str: 숫자를 문자로 바꿔주기 f-str: 중간에 변수를 넣어주기 더 편함 scores = [ {'name':'영수','score':70}, {'name':'영희','score':65}, {'name':'기찬','score':75}, {'name':'희수','score':23}, {'name':'서경','score':99}, {'name':'미주','score':100}, {'name':'병태','score':32} ] for s in scores: name = s['name'] score = s['score'] print(name + '의 점수는 '+str(score)+'점입니다' ) #이 둘은 서로 같은 결과를 나타내 준다. print(f'{name}의 점수는 {score}점입니다') #이 둘은 서..
2023.08.14 -
Python split, int
num = pin.split('-')[1][:1] '-' 기준으로 2번째 chunk의 2번째 문자 전까지 int(num) % 2 == 0: num 문자를 숫자로 변환하여 2로 나누었을때 나머지가 0 def check_gender(pin): num = pin.split('-')[1][:1] if int(num) % 2 == 0: print('female') else: print('male') check_gender('150809-102938') check_gender('150829-202938') check_gender('152459-102938') 세 명의 주민등록번호를 보고 남자인지 여자인지 알아보기
2023.08.14 -
Python enumerate
people = [ {'name': 'bob', 'age': 20}, {'name': 'carry', 'age': 38}, {'name': 'john', 'age': 7}, {'name': 'smith', 'age': 17}, {'name': 'ben', 'age': 27}, {'name': 'bobby', 'age': 57}, {'name': 'red', 'age': 32}, {'name': 'queen', 'age': 25} ] for i, person in enumerate (people): name = person['name'] age = person['age'] print(i, name,age) if i > 2: break
2023.08.14 -
[code 모음] fetch 코드_영화사이트에서 제목, 별점, 코멘트 불러오기
fetch("http://spartacodingclub.shop/web/api/movie").then(res => res.json()).then(data => { let rows = data['movies'] $('#cards').empty() rows.forEach((a) => { console.log(a) let title = a['title'] let desc = a['desc'] let comment = a['comment'] let star = a['star'] let image = a['image'] let star_image = '⭐'.repeat(star) let temp_html = ` ${title} ${desc} ${star_image} ${comment} ` $('#cards').a..
2023.08.09