Here are simple programs. The console version:
# console sales tax program
while True:
price = float(raw_input("Enter purchase price: "))
# prevent division by zero error
if price != 0:
break
else:
print "price can not be zero!"
tax = float(raw_input("Enter sales tax paid: "))
percent = 100 * tax / price
print "You paid %0.3f%s sales tax" % (percent, '%')
Now the Tkinter GUI version:
# Tkinter sales tax program
from Tkinter import *
import tkSimpleDialog
# the basic window
root = Tk()
# create label for result
label1 = Label(root)
# position the label in window
label1.grid(row=0, column=0)
# ask for needed data with dialog window
# the askfloat dialog window makes certain you entered floating point value
# and also prevents you from entering zero which would give divide by zero error
price = tkSimpleDialog.askfloat("Price", "Enter purchase price:", parent=root, minvalue=0.01)
tax = tkSimpleDialog.askfloat("Tax", "Enter sales tax paid:", parent=root)
percent = 100 * tax / price
result = "You paid %0.3f%s sales tax" % (percent, '%')
# display result string in label1
label1.config(text=result)
# event loop needed by GUI, checks for mouse and key events
root.mainloop()