
개발사항 사용자에게 근무시간과 시급을 입력받다 총 급여를 계산한다. 전체 근무시간 중 40시간까지는 일반 시급을 적용한다. 전체 근무시간 중 40시간 초과분은 일반 시급의 1.5 배를 적용한다. 사용자에게 입력받은 값에 대한 정합성 체크가 필요하다. 급여를 계산하는 부분은 함수로 구현한다. def computePay(hours, rate) : if hours > 40 : #근무시간이 40시간 이상이면 #40시간까지는 일반시급으로 계산하고 #40시간 초과분은 시급의 1.5배를 적용 f_regPay = hours * rate f_otPay = (hours - 40.0) * (rate * 0.5) f_totPay = f_regPay + f_otPay else : f_totPay = hours * rate re..

개발사항 사용자에게 근무시간과 시급을 입력받아 총 급여를 계산한다. 전체 근무 시간 중 40시간까지는 일반 시급을 적용한다. 전체 근무 시간 중 40시간 초과분은 일반 시급의 1.5 배를 적용한다. 사용자에게 입력받은 값에 대한 정합성 체크가 필요하다. s_hours = input("Enter Hours : ") #근무시간 s_rate = input("Enter Rate : ") #시급 try: #연산을 위해 실수형으로 형변환 f_hours = float(s_hours) f_rate = float(s_rate) except: #입력값이 숫자형이 아니면 예외처리 print("Error, please enter numeric input") quit() if f_hours > 40 : #근무시간이 40시간 이..

Flask 웹어플리케이션에서 원시 SQL 을 이용하여 RUID 작업을 하는 것은 매우 번거롭고 귀찮은 일이다. SQLAlchemy 를 이용하면 이러한 작업들을 보다 쉽게 처리할 수 있다. 파일명 : 17_sqlalchemy.py from flask import Flask, request, flash, url_for, redirect, render_template from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) # 데이터베이스 파일의 절대경로 입력 app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////home/pi/project/students.sqlite3' app.config['SECRET_KEY'] ..

Flask 는 SQLite 를 내장지원한다. 우선 임시 프로그램을 이용하여 데이터베이스와 connection 을 맺고 테이블을 하나 생성한다. 파일명 : sqlite_temp.py import sqlite3 conn = sqlite3.connect('database.db') print ('Opened database successfully') conn.execute('CREATE TABLE STUDENTS (NAME TEXT, ADDR TEXT, CITY TEXT, PIN TEXT)') print ('Table created successfully') conn.close() 프로그램이 정상 종료 되었다면 'database.db' 라는 파일이 생성되어 있을 것이다. 파일명 : 16_sqlite3.py fr..