Home Work Assignment

+2 Sunday Akinduro · January 23, 2015
for i in range(4, 100, 4):

print (i)

Post a Reply

Replies

- page 1
Oldest  Newest  Rating
0 Bernard Pyc0d333 Parah · January 23, 2015
this should print from 4 to 96.

what is your error? because you just pasted the code without describing your problem
0 jefferson cabrera · February 2, 2015
He did:


for i in range(4, 100, 4):

print (i)

is it possible he gave the variable i a value? beforehand?
+1 rachel laran · February 2, 2015
Nope it doesn't mean or need for you to have the variable i declared before hand..it is a dynamical declaration, that is the variable i is declared on the run and exectution of your program, even u can change the stuff to

    for  me in range(20):
          print  me

what this is insinuating is that you are assigning the iterable in the range(20) to the value me as the loop goes on
+1 Sunday Akinduro · February 5, 2015
Hi Bernard,

It was my solution to the Home Work Assignment that Bucky gave us in the Video. Thanks
0 Bernard Pyc0d333 Parah · February 5, 2015
ouch sorry
0 Bernard Pyc0d333 Parah · February 5, 2015
and Rachel is a python geek, so she can always help out.
+1 rachel laran · February 5, 2015
@Bernard...u aint got yourself, naughty pal, wish i had the priviledge on this site to knock u on the head! lol...thats gonna be awesome, welll im trying lil bits of python programming...and @Sunday Akinduro, i can help when u have pythonic issues
0 Bernard Pyc0d333 Parah · February 5, 2015
haha, you gotta become a moderator to do that, if i we had crowns, you would be the PYTHON QUEEN.
:)
0 Sunday Akinduro · February 5, 2015
Hi Rachel,

Can you please help me with the solution to the pythonic issue below.

Please I need help. I am a starter.

I defined the function below and it works for its purpose. I attempted to bind the function with the layout I created but I am not getting the desired result.

I would like that the user enter the parameters of the function in the Entry field created in the GUI and by clicking the Monthly Tax Payable button, the user will see the result.

Thanks in advance for your help.


from tkinter import *

root = Tk()
root.title('Paye Calculator')
frame = Frame(root)
frame.grid()


def calculate_paye(gross_pay, pension, life_assur):
    annual_tax_payable = (12 * float(gross_pay)) - (
        200000 + (0.2 * 12 * float(gross_pay)) + (12 * float(pension + life_assur)))
    if annual_tax_payable
0 Nishant Kumar Thakur · February 6, 2015
Hi Sunday,

I took your code from previous forum and tweaked it to get it working. 


from Tkinter import *

root = Tk()
root.title('Pay Calculator')
frame = Frame(root)
frame.grid()


def calculate_pay(gross_pay, pension, life_assur):
    annual_tax_payable = (12 * float(gross_pay)) - (
        200000 + (0.2 * 12 * float(gross_pay)) + (12 * float(pension + life_assur)))
    if annual_tax_payable <= 0:
        monthly_tax_payable = (0.01 * 12 * gross_pay) / 12
        print(format(monthly_tax_payable, "8,.2f"))
    elif 0 < annual_tax_payable <= 300000:
        monthly_tax_payable = (0.07 * annual_tax_payable) / 12
        print(format(monthly_tax_payable, "8,.2f"))
    elif 300000 < annual_tax_payable <= 600000:
        monthly_tax_payable = ((300000 * 0.07) + ((annual_tax_payable - 300000) * 0.11)) / 12
        print(format(monthly_tax_payable, "8,.2f"))
    elif 600000 < annual_tax_payable <= 1100000:
        monthly_tax_payable = ((300000 * 0.07) + (300000 * 0.11) + ((annual_tax_payable - 600000) * 0.15)) / 12
        print(format(monthly_tax_payable, "8,.2f"))
    elif 1100000 < annual_tax_payable <= 1600000:
        monthly_tax_payable = ((300000 * 0.07) + (300000 * 0.11) + (500000 * 0.15) + (
            (annual_tax_payable - 1100000) * 0.19)) / 12
        print(format(monthly_tax_payable, "8,.2f"))
    elif 1600000 < annual_tax_payable <= 3200000:
        monthly_tax_payable = ((300000 * 0.07) + (300000 * 0.11) + (500000 * 0.15) + (500000 * 0.19) + (
            (annual_tax_payable - 1600000) * 0.21)) / 12
        print(format(monthly_tax_payable, "8,.2f"))
    elif annual_tax_payable > 3200000:
        monthly_tax_payable = ((300000 * 0.07) + (300000 * 0.11) + (500000 * 0.15) + (500000 * 0.19)+(1600000 * 0.21) + (
            (annual_tax_payable - 3200000) * 0.24)) / 12
        print(format(monthly_tax_payable, "8,.2f"))
    else:
        print('No tax due')
        monthly_tax_payable = 0
        
    return format(monthly_tax_payable, "8,.2f")

def getInputAndSetOutputOnUI():
    gross_pay = float(gross_payEntry.get())
    pension = float(pensionEntry.get())
    life_assurance_contri = float(life_assuranceEntry.get())
    monthly_tax_payable = calculate_pay(gross_pay, pension, life_assurance_contri)
    resultString.set("Monthly Tax : "+ monthly_tax_payable)
    
    

gross_payEntry = Entry(frame, text="Enter Monthly Gross Pay")
gross_payEntry.grid(row=0, column=1)
gross_payLabel = Label(frame, text="Monthly Gross Pay=NGN")
gross_payLabel.grid(row=0, column=0, sticky=E)

pensionEntry = Entry(frame, text='Monthly Pension Contribution')
pensionEntry.grid(row=1, column=1)
pensionLabel = Label(frame, text="Monthly Pension=NGN")
pensionLabel.grid(row=1, column=0, sticky=E)

life_assuranceEntry = Entry(frame, text='Monthly Life Assurance Contribution')
life_assuranceEntry.grid(row=2, column=1)
life_assuranceLabel = Label(frame, text="Monthly Life Assurance Contribution=NGN")
life_assuranceLabel.grid(row=2, column=0, sticky=E)

monthly_tax_payableButton = Button(frame, text="Monthly Tax Payable", command=getInputAndSetOutputOnUI)
monthly_tax_payableButton.grid(row=3, column=1, sticky=E)

resultString = StringVar()
resultString.set("Enter details and click button to get Monthly Tax")
resultField = Label(frame, textvariable=resultString)
resultField.grid(row=3, column=0, sticky=E)

root.mainloop()
  • 1
  • 2

Python

106,989 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator