I made a payroll program in Python!

1.First of all

As the title suggests, I made a program to manage hourly wages in Python (^^;) Most of it has been completed and I would like to publish it.

2. The process up to program creation.

What came to your mind, how much did you earn this month after your part-time job ended in the middle of the night? It was the beginning that I thought. When I noticed, the birds were singing and the sun was shining (^^;) It didn't end on that day alone, so I was able to complete it to some extent today after nearly three hours of finishing my part-time job! Maybe there is a bug ... There is no functionality at all w

It's such a program, but if it helps someone, m (_ _) m

3. About the program

4. Actual program

salary.py


#-*- coding:utf-8 -*-

import sqlite3
import sys
import datetime

#Choose what you want to do from now on
def  checksalary_or_addtime():
	print "Enter "C" to check your salary up to this month"
	print "Enter "A" to add new working hours"
	print "* Note: In case of addition, you can only enter the amount for this year."
	push_word = raw_input(">>> ")
	if push_word == "C" or push_word == "c":
		print "--------------------------------------------------------------"
		print "\n Check your salary to date this month\n"
		check_no = 1
	elif push_word == "A" or push_word == "a":
		check_no = 2
	else:
		print "\n Confirmed incorrect input. Please try again\n"
		print "--------------------------------------------------------------"
		check_no = 0
	return check_no

#==== Function for adding new working hours|START====
def alert01(today):
	print "--------------------------------------------------------------"
	print "\n * Caution *"
	print "today%d years%d month%It's d days.\n Currently you can enter\n" % (today.year,today.month,today.day)
	if today.month >= 4:
		print "『%April 1, d year ~%d years%d month%d day ”" % (today.year,today.year,today.month,today.day)
	else:
		print "『%April 1, d year ~%d years%d month%d day ”" % (today.year-1,today.year,today.month,today.day)
	print "Only during.\n If you try to enter any other period, you will get an incorrect entry.\n"
	print "--------------------------------------------------------------"

#Check if the input was between January and December
def check_month(input_word,today):
	if input_word <= 0 or input_word >12:
				return 0
	else:
		if today.month >= 4:
			if input_word <4 or today.month < input_word:
				print "The entered month is not applicable"
				return 0
		else:
			return 1

#Judge whether the entered characters are numerical values [Month version]
def check_inputword_month(input_word,today):
	check_no = 0
	while check_no == 0:
		if input_word.isdigit() == True:
			input_word = int(input_word)
			check_no = check_month(input_word,today)
		else:
			check_no = 0
		if check_no == 0:
			print "\n Confirmed incorrect input. Please try again"
			print "--------------------------------------------------------------"
			print"Please enter the month you want to add"
			input_word = raw_input(">>> ")
	return input_word

#Make sure the date entered is within the correct date range
def check_day(input_word,input_month,input_year):
	if input_word <= 0 or input_word >31:
		return 0
	else:
		if input_month == 2:
			if input_year%4 == 0:
				if input_year%100 == 0:
					if input_year%400 == 0:
						if input_word>29:
							return 0
						else:
							return 1
					else:
						if input_word>28:
							return 0
				else:
					if input_word>29:
						return 0
			else:
				if input_word>28:
					return 0
		elif input_month == 4 or input_month == 6 or input_month == 9 or input_month == 11:
			if input_word>30:
				return 0
			else:
				return 1
		else:
			if input_word>31:
				return 0
			else:
				return 1


#Judge whether the entered characters are numerical values [Day version]
def check_inputword_day(input_word,today,input_month,input_year):
	check_no = 0
	while check_no == 0:
		if input_word.isdigit() == True:
			input_word = int(input_word)
			if today.month == input_month:
				if today.day < input_word or input_word <= 0:
					check_no = 0
				else:
					check_no = 1
			else:
				check_no = check_day(input_word,input_month,input_year)
		else:
			check_no = 0
		if check_no == 0:
			print "\n Confirmed incorrect input. Please try again"
			print "--------------------------------------------------------------"
			print"Enter the month you want to add."
			input_word = raw_input(">>> ")
	return input_word

#Judge whether the entered characters are numerical values [Time version]
def check_inputword_time(input_word):
	check_no = 0
	while check_no == 0:
		if input_word.isdigit() == True:
			input_word = int(input_word)
			check_no = 1
		else:
			check_no = 0
		if check_no == 0:
			print "\n Confirmed incorrect input. Please try again"
			print "--------------------------------------------------------------"
			print"Enter the month you want to add."
			input_word = raw_input(">>> ")
	return input_word

#Confirm to continue
def  check_continue():
	print "Enter "Y" to continue as it is, or "N" to stop the program."
	push_word = raw_input(">>> ")
	if push_word == "Y" or push_word == "y":
		check_no = 1
	elif push_word == "n" or push_word == "N":
		check_no = 2
	else:
		print "\n Confirmed incorrect input. Please try again\n"
		print "--------------------------------------------------------------"
		check_no = 0
	return check_no

#==== Function for adding new working hours|FINISH====

#==== Function for checking salary up to the present of this month|START====

#Check if the entered year is abnormal
def check_year_cs(input_word,today):
	if input_word > today.year or input_word <= 0:
		return 0
	else:
		return 1

#Judge whether the entered characters are numerical values [Year version]
def check_inputword_year_cs(input_word,today):
	check_no = 0
	while check_no == 0:
		if input_word.isdigit() == True:
			input_word = int(input_word)
			check_no = check_year_cs(input_word,today)
		else:
			check_no = 0
		if check_no == 0:
			print "\n Confirmed incorrect input. Please try again"
			print "--------------------------------------------------------------"
			print"Please enter the month you want to check"
			input_word = raw_input(">>> ")
	return input_word

#Check if the input was between January and December
def check_month_cs(input_word,today,input_word_year):
	if input_word <= 0 or input_word >12:
		return 0
	else:
		if input_word_year == today.year:
			if input_word > today.month:
				return 0
			else:
				return 1
		else:
			return 1

#Judge whether the entered characters are numerical values [Month version]
def check_inputword_month_cs(input_word,today,input_word_year):
	check_no = 0
	while check_no == 0:
		if input_word.isdigit() == True:
			input_word = int(input_word)
			check_no = check_month_cs(input_word,today,input_word_year)
		else:
			check_no = 0
		if check_no == 0:
			print "\n Confirmed incorrect input. Please try again"
			print "--------------------------------------------------------------"
			print"Please enter the month you want to check"
			input_word = raw_input(">>> ")
	return input_word

def check_day_cs(input_month,input_year):
	if input_month == 2:
		if input_year%4 == 0:
			if input_year%100 == 0:
				if input_year%400 == 0:
					return 29
				else:
					return 28
			else:
				return 29
		else:
			return 28
	elif input_month == 4 or input_month == 6 or input_month == 9 or input_month == 11:
		return 30
	else:
		return 31

#==== Function for checking salary up to the present of this month|FINISH====

#Check salary up to this month
def check_salary(db,cur):
	today = datetime.date.today()

	print "Please enter the year you want to check your salary"
	check_salary_year = raw_input(">>> ")
	check_salary_year = check_inputword_year_cs(check_salary_year,today)
	print check_salary_year

	print "Please enter the month you want to check your salary"
	check_salary_month = raw_input(">>> ")
	check_salary_month = check_inputword_month_cs(check_salary_month,today,check_salary_year)

	if check_salary_month == today.month and check_salary_year == today.year:
		j = today.day + 1
	else:
		check_salary_day = check_day_cs(check_salary_month,check_salary_year)
		j = check_salary_day + 1
	n_time = [0] * j
	s_time = [0] * j
	sum_n_time = 0
	sum_s_time = 0
	for i in xrange(1,j):
		sql = "select * from sms where days = '%d years%d month%d day'" % (check_salary_year,check_salary_month,i)
		row = cur.execute(sql)
		for salary_time in row:
			n_time[i]=salary_time[1]
			s_time[i]=salary_time[2]
	for i in xrange(1,today.day+1):
		sum_n_time = sum_n_time + n_time[i]
		sum_s_time = sum_s_time + s_time[i]
	sum_salary = sum_n_time * 868 + sum_s_time * 868 * 1.35
	print "--------------------------------------------------------------"
	if check_salary_month == today.month and check_salary_year == today.year:
		print "your%d years%d month%Salary up to date d...\n\n%d yen\n\is n" % (check_salary_year,check_salary_month,today.day,sum_salary)
		
	else:
		print "your%d years%d month salary...\n\n%d yen\n\is n" % (check_salary_year,check_salary_month,sum_salary)
	print "--------------------------------------------------------------"
	

#Added new working hours
def add_time(db,cur):
	today = datetime.date.today()
	alert01(today)

	print "Please enter the month you want to add"
	input_month = raw_input(">>> ")
	input_month = check_inputword_month(input_month,today)
	input_year = today.year
	if today.month < 4:
		if input_month >= 4:
			input_year = input_year - 1
	print "Please enter the date you want to add"
	input_day = raw_input(">>> ")
	input_day = check_inputword_day(input_day,today,input_month,input_year)
	print "--------------------------------------------------------------"
	print "\n The day you want to add...\t%d years%d month%d day\t" % (input_year,input_month,input_day)
	print "--------------------------------------------------------------"
	check_no = 0
	while check_no == 0:
		check_no = check_continue()
	if check_no == 1:
		print "--------------------------------------------------------------"
		print "\n Check your salary to date this month\n"
	elif check_no == 2:
		print "confirmed. Exit the program"
		sys.exit()

	print "\n%d years%d month%Please enter the total number of hours worked on d days" % (input_year,input_month,input_day)
	input_totaltime = raw_input(">>> ")
	input_totaltime = check_inputword_time(input_totaltime)
	print "--------------------------------------------------------------"
	print "\n%Specially added in d hours(Midnight salary etc.)Please enter the number of hours in the time zone." % input_totaltime
	input_sp_time = raw_input(">>> ")
	input_sp_time = check_inputword_time(input_sp_time)			
	input_no_time = input_totaltime - input_sp_time
	print "--------------------------------------------------------------"
	print "\n Save the following contents in the database.\n"
	print "--------------------------------------------------------------"
	print "\n%d years%d month%d day" % (input_year,input_month,input_day)
	print "Total number of hours:%d" % input_totaltime
	print "Number of hours in the time zone subject to special addition:%d" % input_sp_time
	print "--------------------------------------------------------------"
	#-----------Note-----------
	#Now make sure you've already entered it on the same date before and ask if you want to overwrite it if it's entered.
	#For the dates that have already been entered, select only overwrite save. It's annoying.
	#If already entered"Y", If not already entered"N"return it.
	sql = "select case when days = '%d years%d month%d day' then 'Y' else 'N' end from sms;" % (input_year,input_month,input_day)
	row = cur.execute(sql)
	for double_check in row:
		if double_check[0] == "Y":
			print "Already%d years%d month%Data has been entered on day d."
			print "Do you want to continue the update work?"
			check_no = 0
			while check_no == 0:
				check_no = check_continue()
				if check_no == 1:
					print "confirmed. Let's update the data"
					sql = "update sms set n_wt = %d and s_wt = %d where days = '%d years%d month%d day'" % (input_no_time,input_sp_time,input_year,input_month,input_day)
					cur.execute(sql)
					db.commit()
					print "The data update is complete. Do you want to continue typing?"
				elif check_no == 2:
					print "confirmed. Exit the program"
					sys.exit()
		elif double_check[0] == "N":
			sql = "insert into sms values('%d years%d month%d day',%d,%d)" % (input_year,input_month,input_day,input_no_time,input_sp_time)
			cur.execute(sql)
			db.commit()
			print("Added data to the database. Do you want to continue typing?")
	check_no = 0
	while check_no == 0:
		check_no = check_continue()
	if check_no == 1:
		print "--------------------------------------------------------------"
		print "\n adds to the database.\n"
		return 2
	elif check_no == 2:
		print "confirmed. Exit the program. Thank you for your hard work"
		cur.close()
		db.close()
		sys.exit()

#Main
if __name__ == '__main__':
	db = sqlite3.connect("salary.db")
	cur = db.cursor()
	sql = "create table sms(days,n_wt,s_wt);"

	try:
		cur.execute(sql)
		print "--------------------------------------------------------------"
		print "\n Created database..."
		print "Successful access to the database"
		print "--------------------------------------------------------------"
	except sqlite3.OperationalError:
		print "--------------------------------------------------------------"
		print "\n The database was successfully accessed\n"
		print "--------------------------------------------------------------"

	check_no = checksalary_or_addtime()

	while check_no == 0:
		check_no = checksalary_or_addtime()

	if check_no == 1:
		check_salary(db,cur)
	elif check_no == 2:
		while check_no == 2:
			check_no == add_time(db,cur)

5. Impressions

There are many things to study by creating this program, I knew it, but I realized that I was still immature (^^;) Also, after all, the user does not always get the input as expected, so I felt that it was quite annoying to have to make a judgment every time I prompted for input (^) ^;) But after all it's fun! !!

Recommended Posts

I made a payroll program in Python!
I made a Caesar cryptographic program in Python.
I made a prime number generation program in Python
I made a prime number generation program in Python 2
I made a python text
I made a program to check the size of a file in Python
I made a Line-bot using Python!
I made a fortune with Python.
I made a daemon with Python
When writing a program in Python
I made a simple typing game with tkinter in Python
I made a quick feed reader using feedparser in Python
I tried "a program that removes duplicate statements in Python"
I made a puzzle game (like) with Tkinter in Python
I made a character counter with Python
Write a Caesar cipher program in Python
I made a Hex map with Python
After studying Python3, I made a Slackbot
I created a password tool in Python.
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a neuron simulator with Python
I made a program that solves the spot the difference in seconds
I made a prime number table output program in various languages
〇✕ I made a game
I made a program to collect images in tweets that I liked on twitter with Python
I made a python dictionary file for Neocomplete
I made a competitive programming glossary with Python
A memo that I wrote a quicksort in Python
I made a GUI application with Python + PyQt5
I want to create a window in Python
I tried playing a typing game in Python
I made a Twitter fujoshi blocker with Python ①
I wrote a class in Python3 and Java
A program that removes duplicate statements in Python
[Python] I made a Youtube Downloader with Tkinter.
[Memo] I tried a pivot table in Python
A simple Pub / Sub program note in Python
I tried adding a Python3 module in C
I made a bin picking game with Python
I made a Mattermost bot with Python (+ Flask)
I made a Python Qiita API wrapper "qiipy"
I made a web application in Python that converts Markdown to HTML
I made a Discord bot in Python that translates when it reacts
I made a script in python to convert .md files to Scrapbox format
[IOS] I made a widget that displays Qiita trends in Pythonista3. [Python]
Take a screenshot in Python
I want to embed a variable in a Python string
I want to easily implement a timeout in python
I made a Twitter BOT with GAE (python) (with a reference)
I wrote python in Japanese
Create a function in Python
Create a dictionary in Python
Write a super simple molecular dynamics program in python
I made a login / logout process using Python Bottle.
Receive dictionary data from a Python program in AppleScript
I made a Christmas tree lighting game with Python
I made blackjack with python!
I want to write in Python! (2) Let's write a test
I made a net news notification app with Python