1. 寫一個程序,輸入任何一個公民的月收入和五險一金,能夠計算他應繳納的個人所得稅。用C語言
假定5險一金固定是1000元,起征點是3500,程序如下:
#include <stdio.h>
int main(int argc, char *argv[])
{
float money,temp,total,t;
租察穗printf("請輸入工資收入:");
scanf("%f",&money);
t=money-3500-1000; // 全月收入總額-1000(五險一金)-3500(現階段個稅起征點)
if (t<1500)
temp=t*0.03;
else
if (t<4500)
沒閉temp=1500*0.03+(t-1500)*0.1;
else
if (t<9000)
temp=1500*0.03+3000*0.1+(t-4500)*0.2;
else
if (t<35000)
temp=1500*0.03+3000*0.1+4500*0.2+(t-9000)*0.25;
else if (t<55000)
temp=1500*0.03+3000*0.1+4500*0.2+26000*0.25+(t-35000)*0.3;
else if (t<80000)
temp=1500*0.03+3000*0.1+4500*0.2+26000*0.25+20000*0.3+(t-55000)*0.35;
else
temp=1500*0.03+3000*0.1+4500*0.2+26000*0.25+20000*0.3+25000*0.35+(t-80000)*0.45;
total=money-temp;
printf("該工資弊卜扣除%8.2f的稅收後,實際工資為:%8.2f\n",temp,total);
return 0;
}
2. 如何用python算稅收
應稅所得兆禪段額=扣除三險一金後襲爛月收入-扣除標准,
三險一金繳納的基準工資上限為7662 ;超過,就按照7662繳納。
計算個人所得稅
有納稅所得額可能小於3500要先判斷納稅所得額是否為負數;
正數根據公式:應納個人所得稅稅額=全月應納稅族譽所得額x適用稅率速算扣除數個稅。
3. 求助,用python編寫一個模擬個人所得稅計算器程序,數據看圖
sal=float(input('請輸入當月稅前工資:'))
S=sal-3500
if 0<S<=1500:
L=S*0.03
print('應納枝察租稅%.2f元'%L)
elif 1500<S<=4500:
L=1500*0.03+(S-1500)*0.1
print('應納稅%.2f元'%L)
elif 4500<S<=9000:
L=1500*0.03+3000*0.1+(S-4500)*0.2
print('應納稅%.2f元'%L)
elif 9000<S<=35000:
L=1500*0.03+3000*0.1+4500*0.2+(S-9000)*0.25
print('應納沒尺稅%.2f元'%L)
elif 35000<S<=55000:
L=1500*0.03+3000*0.1+4500*0.2+26000*0.25+(S-35000)*0.3
print('應納稅%.2f元'%L)
elif 55000<S<猛兆=80000:
L=1500*0.03+3000*0.1+4500*0.2+26000*0.25+20000*0.3+(S-55000)*0.35
print('應納稅%.2f元'%L)
elif S>80000:
L=1500*0.03+3000*0.1+4500*0.2+26000*0.25+20000*0.3+25000*0.35+(S-80000)*0.45
print('應納稅%.2f元'%L)
else:
print('未到起征點,不用交稅')
4. 求一個PYTHON案例
# 以下程序可能要安裝OpenCV2.0(並編譯好並配置好環境)以及Xvid解碼器才能運行
# _*_coding: cp936_*_
import cv
capture = cv.CreateFileCapture("tmp.avi")
#請確保當前目錄下有tmp.avi文件
fps = cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FPS)
totalFrameNumber =cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_COUNT)
frameWidth = cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH)
frameHeight = cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT)
print fps, totalFrameNumber, frameWidth, frameHeight
frame = cv.QueryFrame(capture)
while frame:
cv.ShowImage('Title', frame)
frame = cv.QueryFrame(capture)
if cv.WaitKey(1000 / fps) == 27:# ESC鍵退出視頻播放
cv.DestroyWindow('Title')
break
一個文件夾整理工具wxPython版本(不清楚軟體用法情況下可以打開該軟體看看界面但請不要使用裡面的功能,後果自負。)
# -*- coding: cp936 -*-
# file:aa.py
import os, shutil, sys
import wx
sourceDir = ''
sourceFiles = ''
preWord = 0
def browse(event):
global sourceDir, textPreWord, textDirName
dialog = wx.DirDialog(None, u'選擇待處理文件夾', style = wx.OPEN)
if dialog.ShowModal() == wx.ID_OK:
sourceDir = dialog.GetPath().strip('\"')
textDirName.SetLabel(sourceDir)
dialog.Destroy()
textPreWord.SetFocus()
def okRun(event):
global preWord, sourceDir, sourceFiles, textPreWord
preWord = int(textPreWord.GetValue())
if preWord <= 0:
wx.MessageBox(u'請正確輸入前綴字元個數!', u'出錯啦', style = wx.ICON_ERROR | wx.OK)
textPreWord.SetFocus()
return
sourceDir = textDirName.GetValue()
sourceFiles = os.listdir(sourceDir)
for currentFile in sourceFiles:
tmp = currentFile
currentFile = sourceDir + '\\' + currentFile
currentFile = currentFile.strip('\"')
if os.path.isdir(currentFile):
continue
targetDir = '%s\\%s'%(sourceDir, tmp[:preWord])
if not os.path.exists(targetDir):
os.mkdir(targetDir)
shutil.move(currentFile, targetDir)
wx.MessageBox(u'任務完成!', u'好消息', style = wx.ICON_ERROR | wx.OK)
def onChange(event):
global dir1, textDirName
p = dir1.GetPath()
textDirName.SetLabel(p)
app = wx.App(0)
win = wx.Frame(None, title = u'文件整理', size = (400, 450))
bg = wx.Panel(win)
btnBrowse = wx.Button(bg, label = u'瀏覽')
btnBrowse.Bind(wx.EVT_BUTTON, browse)
btnRun = wx.Button(bg, label = u'整理')
btnRun.Bind(wx.EVT_BUTTON, okRun)
dir1 = wx.GenericDirCtrl(bg, -1, dir='', style=wx.DIRCTRL_DIR_ONLY)
tree = dir1.GetTreeCtrl()
dir1.Bind(wx.wx.EVT_TREE_SEL_CHANGED, onChange, id = tree.GetId())
textPreWord = wx.TextCtrl(bg)
textDirName = wx.TextCtrl(bg)
textPreWord.SetFocus()
class MyFileDropTarget(wx.FileDropTarget):#聲明釋放到的目標
def __init__(self, window):
wx.FileDropTarget.__init__(self)
self.window = window
def OnDropFiles(self, x, y, filenames):#釋放文件處理函數數據
for name in filenames:
if not os.path.isdir(name):
wx.MessageBox(u'只能選擇文件夾!', '出錯啦', style = wx.ICON_ERROR | wx.OK)
return
self.window.SetValue(name)
dt = MyFileDropTarget(textDirName)
textDirName.SetDropTarget(dt)
hbox0 = wx.BoxSizer()
hbox0.Add(dir1, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 5)
hbox1 = wx.BoxSizer()
hbox1.Add(textDirName, proportion = 1, flag = wx.EXPAND, border = 5)
hbox1.Add(btnBrowse, proportion = 0, flag = wx.LEFT, border = 5)
hbox2 = wx.BoxSizer()
hbox2.Add(textPreWord, proportion = 1, flag = wx.EXPAND, border = 5)
hbox2.Add(btnRun, proportion = 0, flag = wx.LEFT, border = 5)
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(hbox0, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 5)
vbox.Add(wx.StaticText(bg, -1, u'\n 選擇待處理文件夾路徑:'))
vbox.Add(hbox1, proportion = 0, flag = wx.EXPAND | wx.ALL, border = 5)
vbox.Add(wx.StaticText(bg, -1, u'\n\n 前綴字元個數:'))
vbox.Add(hbox2, proportion = 0, flag = wx.EXPAND | wx.ALL, border = 5)
vbox.Add(wx.StaticText(bg, -1, u'\n'))
bg.SetSizer(vbox)
win.Center()
win.Show()
app.MainLoop()
#py2exe打包代碼如下:
from distutils.core import setup
import py2exe
setup(windows=["aa.py"])
打包好了之後有18Mb。
一個文件內容批量替換摸查器(wxPython版本):
# _*_ coding:cp936 _*_
from string import join, split
import os
import wx
def getAllFiles(adir):
tmp = []
for parent, dirs, files in os.walk(adir):
for afile in files:
tmp.append(os.path.join(parent, afile))
return tmp
def browse(event):
dialog = wx.DirDialog(None, '選擇待處理文件夾', style=wx.OPEN)
if dialog.ShowModal() == wx.ID_OK:
aDir = dialog.GetPath()
textDir.SetLabel(aDir)
dialog.Destroy()
def check():
promp.SetForegroundColour('#FF0000')
promp.SetLabel(' 搜索中...')
listFound.ClearAll()
tmp = []
files = getAllFiles(textDir.GetValue())
for filename in files:
try:
afile = open(filename, 'r')
except IOError:
print '打開文件錯誤。'
continue
try:
content = afile.read().decode('utf-8')
afile.close()
except:
try:
afile = open(filename, 'r')
content = afile.read().decode('cp936')
afile.close()
except:
continue
if textNeedChar.GetValue() in content:
tmp.append(filename)
listFound.InsertStringItem(0, filename)
parentDir.SetForegroundColour('#FF0000')
# parentDir.SetLabel(' 正在搜索:'+filename)
return tmp
def onFind(event):
check()
parentDir.SetLabel(' 搜索結果:')
promp.SetLabel(' 任務完成。')
wx.MessageBox(listFound.GetItemCount() and '任務完成,找到%d個文件。' % listFound.GetItemCount()
or '未找到包含"%s"的文件!' % textNeedChar.GetValue().encode('cp936'), '查找結束',
style=wx.ICON_INFORMATION | wx.OK)
def onReplace(event):
dg = wx.TextEntryDialog(bg, '替換成:', '提示', style=wx.OK | wx.CANCEL)
if dg.ShowModal() != wx.ID_OK:
return
files = check()
userWord = dg.GetValue()
#if not userWord:
#wx.MessageBox('請輸入要替換為何字!', style=wx.ICON_ERROR | wx.OK)
#onReplace(event)
#return
for filename in files:
try:
afile = open(filename, 'r')
except IOError:
print '打開文件錯誤。'
continue
try:
content = afile.read().decode('utf-8')
afile.close()
except:
try:
afile = open(filename, 'r')
content = afile.read().decode('cp936')
afile.close()
except IOError:
print '打開文件錯誤。'
continue
content = content.replace(textNeedChar.GetValue(), userWord)
try:
content = content.encode('utf-8')
except:
pass
open(filename, 'w').write(content)
parentDir.SetLabel(' 替換的文件:')
promp.SetLabel(' 任務完成。')
wx.MessageBox(listFound.GetItemCount() and '任務完成,替換了%d個文件。' % listFound.GetItemCount()
or '未找到包含"%s"的文件!' % textNeedChar.GetValue().encode('cp936'), '替換結束', style=wx.ICON_INFORMATION | wx.OK)
app = wx.App(0)
win = wx.Frame(None, title='文件整理', size=(400, 450))
bg = wx.Panel(win)
btnBrowse = wx.Button(bg, label='瀏覽')
btnBrowse.Bind(wx.EVT_BUTTON, browse)
btnFind = wx.Button(bg, label='查找')
btnFind.Bind(wx.EVT_BUTTON, onFind)
btnFind.SetDefault()
btnReplace = wx.Button(bg, label='替換')
btnReplace.Bind(wx.EVT_BUTTON, onReplace)
textNeedChar = wx.TextCtrl(bg, value='你好')
textDir = wx.TextCtrl(bg, value='E:\Workspace\Python\Python\e')
parentDir = wx.StaticText(bg)
promp = wx.StaticText(bg)
listFound = wx.ListCtrl(bg, style=wx.VERTICAL)
class MyFileDropTarget(wx.FileDropTarget):#聲明釋放到的目標
def __init__(self, window):
wx.FileDropTarget.__init__(self)
self.window = window
def OnDropFiles(self, x, y, filenames):#釋放文件處理函數數據
for name in filenames:
'''if not os.path.isdir(name):
wx.MessageBox('只能選擇文件夾!', '出錯啦', style=wx.ICON_ERROR | wx.OK)
return '''
self.window.SetValue(name)
dt = MyFileDropTarget(textDir)
textDir.SetDropTarget(dt)
hbox1 = wx.BoxSizer()
hbox1.Add(textDir, proportion=1, flag=wx.EXPAND, border=5)
hbox1.Add(btnBrowse, proportion=0, flag=wx.LEFT, border=5)
hbox2 = wx.BoxSizer()
hbox2.Add(textNeedChar, proportion=1, flag=wx.EXPAND, border=5)
hbox2.Add(btnFind, proportion=0, flag=wx.LEFT, border=5)
hbox2.Add(btnReplace, proportion=0, flag=wx.LEFT, border=5)
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(wx.StaticText(bg, -1, '\n 選擇待處理文件夾(可拖動文件夾到下面區域中):'))
vbox.Add(hbox1, proportion=0, flag=wx.EXPAND | wx.ALL, border=5)
vbox.Add(wx.StaticText(bg, -1, '\n\n 要替換 / 查找的文字:'))
vbox.Add(hbox2, proportion=0, flag=wx.EXPAND | wx.ALL, border=5)
vbox.Add(promp, proportion=0, flag=wx.EXPAND | wx.ALL, border=5)
vbox.Add(parentDir, proportion=0, flag=wx.EXPAND | wx.ALL, border=5)
vbox.Add(listFound, proportion=1,
flag=wx.EXPAND | wx.LEFT | wx.BOTTOM | wx.RIGHT, border=5)
bg.SetSizer(vbox)
win.Center()
win.Show()
app.MainLoop()