Python
-
flask 파이참 템플릿, code snippets이 안불러와질때Python 2024. 7. 9. 13:52
flask 로 웹페이지에 가위바위보 게임을 구현하는 코드를 만들고 있는데 f로 시작하는 flask code snippets이 자동으로 불러와지지 않았다. vscode에서는 되는데.. 예를 들어, ffor (flask for) 근데 파이참에서는 안됨.. 경원튜터님이 보내주신 방법으로 해보니 해결되었다. [방법]1. click here ←클릭하고 settings.jar 다운받기 2. 파이참 > file > Manage IDE Settings > Import Settings... 클릭 다운받은 파일 settings.jar 선택 3. 파이참 재시작 (자동으로 됨) 4. File > Invalidate Chaches... 5. Just Restart 클릭 사실 난 Invalidate and Restart를..
-
파이썬, class로 sns platform 코드2 input으로 객체 생성Python 2024. 7. 6. 00:20
이전 파이썬, class를 사용하여 만들었던 간단한 sns platform 코드에 회원 정보를 인풋으로 입력받아서 가져오는 코드를 추가했다. class Member, class Post 생성 부분은 거의 동일하다.import hashlibclass Member: def __init__(self, name, username, password): self.name = name self.username = username self.password = self._hash_password(password) # 좀 더 간결한 코드로 수정했다 def _hash_password(self, password): return hashlib.sha256(passwo..
-
python, class, 인스턴스 생성 - 간단한 sns platform 코딩Python 2024. 7. 5. 19:44
파이썬, class를 사용하여 간단한 sns platform의 유저 정보를 받는 코딩 문제 저번 과제 피드백이 절차지향적으로 코드를 잘 짰다는 걸 보면.. 아마도.. 객체지향적으로는 단단함이 부족하다는 의미가 아닐까 싶었다.. 그래서 이번 과제가 class를 이용한 과제인만큼 객체지향적으로 코드를 짜보자고 다짐했다. 구현해야 할 조건은 아래와 같다.1. Member 클래스회원 이름 (name)회원 아이디 (username회원 비밀번호 (password)*회원 정보를 print해주는 display: 회원이름과 아이디만 보여주고 비밀번호는 보여줘서는 안됨 2. Post 클래스게시물 제목 (title)게시물 내용 (content)작성자 (author) : 회원의 username 이 저장되어야 함!3. 회원 ..
-
가위 바위 보 게임 코드 만들기Python 2024. 7. 4. 03:22
컴퓨터와 유저가 대결을 하는 가위바위보 게임이다. 가장 먼저 컴퓨터가 가위 바위 보 중 하나를 랜덤으로 뽑아야 해서 random 모듈을 import 했다.import randomprint("게임을 시작합니다.") 오늘 세션 이후 추가해준 코드win = 0lose = 0draw = 0option: ["가위", "바위", "보"] ["가위", "바위", "보"]가 반복적으로 여러번 나오니까 option list로 묶어줬고 마지막에 승, 패, 무승부 결과를 알려주기 위해 win, lose, draw 변수를 추가했다. get_computer_choice() : 컴퓨터가 선택한 가위 바위 보 함수로, 가위 바위 보 중 하나를 랜덤으로 뽑아야하므로 option을 인수로 받는 random.choice를 썼다. ..
-
파이썬으로 업다운 게임 만들기Python 2024. 7. 2. 22:57
업다운 게임 코드 짜기 일단 컴퓨터가 유저가 맞출 숫자를 하나 랜덤으로 뽑아야 하니 random 모듈을 import 했다.게임이 시작될 때마다 1부터 100사이의 숫자 하나를 뽑는 건 계속 반복되는 일이니까 제일 먼저 함수로 만들어두고.import randomdef up_down_game(): return random.randint(1, 100) attempts는 시도 횟수 때문에 만들어줬는데, 처음에는 그냥 attempts = 0 이렇게만 했다. 근데 만들고보니 총 시도 횟수를 구해야 해서 나중에 total_attempts 리스트를 추가했다. 컴퓨터가 랜덤으로 숫자를 뽑는게 게임의 가장 첫번째 순서이기 때문에total_attempts = []print("UpDown 게임을 시작합니다.")while..
-
파이썬 문법 심화Python 2024. 6. 30. 07:54
자주 사용되는 모듈 및 패턴 1. type()integer = 10float_ = 1.23string = "hello world!!"list_ = [1, 2, 3]tuple_ = (1, 2, 3)set_ = {1, 2, 3}dictionary = {"key": "value"}boolean = Trueprint(type(integer)) # print(type(float_)) # print(type(string)) # print(type(list_)) # print(type(tuple_)) # print(type(set_)) # print(type(dictionary)) # print(type(boolean)) # a = 1b = '1' 이럴 경우 숫자 1인지 문자 1인지 알 수 없는데 이때 type(..
-
파이썬 문법 기초Python 2024. 6. 28. 21:00
반복문, 조건문 활용 예제 1people = [ {'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 >..
-
Python, SQLite, SQLAlchemy, Database 조작Python 2024. 6. 27. 18:45
SQLite Python에는 기본적으로 SQLite가 내장되어 있으므로 별도 설치 없이 VScode에서 파일이름.db 형식으로 파일을 만들기만 하면 손쉽게 사용할 수 있다. (venv 라이브러리 이용) 터미널, 설치pip install Flask-SQLAlchemy app.py에 Flask와 Database를 연결하는 코드 입력from flask import Flaskimport osfrom flask_sqlalchemy import SQLAlchemybasedir = os.path.abspath(os.path.dirname(__file__))app = Flask(__name__)app.config['SQLALCHEMY_DATABASE_URI'] =\ 'sqlite:///' + os.path..