lundi 25 janvier 2016

Powerball winnings using if else statements in python

I am trying to solve a question regarding lottery winnings. As we all know that after a person wins a lottery amount, they don't always take the full amount. They get taxed in different brackets and I am trying to create a python program which tells us the amount that we are taxed on our winnngs.

Before any taxes are assessed, the winner is given a standard deduction of $6300 and a personal exemption of $4000. So before we find out how much amount is taxed, we find the taxable amount by the formula

taxablewinnings = winnings-(Standard Deduction+Personal Exemption)

After that the winning amount is categorized in these amount brackets.

$0 to $9,225----10%

$9,225 to $37,450----15%

$37,450 to $90,750----25%

$90,750 to $189,300----28%

$189,300 to $411,500----33%

$411,500 to $413,200----35%

$413,200+ ----39.6%

For example. If a person wins $54000 taxablewinnings = $54000-$6300-$4000 =$43,700 is the amount which will be taxed. Of that amount:

$9225 is taxed at 10% = $922.50 leaving $34,475 not yet taxed

$28,225 is taxed at 15% = $4233.75 leaving $6,250 not yet taxed

$6,250 is taxed at 25% = $1,562.50

Total owed = 922.5 + 4233.75 + 1562.5 = $6718.75 (or $6,719 rounded)

Here is my code.

winnings = float(input("Please enter your Winning amount"))                

tax = 0                                                                    
standardDeduction = 6300                                                   
personalExemption = 4000                                                   


taxablewinnings = winnings - (standardDeduction+personalExemption)  



if taxablewinnings > 0 and taxablewinnings <= 9225:                    
    rate1 = 9225*0.10                                                  
    remainder1 = taxablewinnings-9225                                  

if taxablewinnings > 9225 and taxablewinnings <= 37450:                
    rate2 = remainder1*0.15                                            
    remainder2 = taxablewinnings-37450                                 

if taxablewinnings > 37450 and taxablewinnings <= 90750:               
    rate3 = remainder2*0.25                                            
    remainder3 = taxablewinnings-90750                                 

if taxablewinnings > 90750 and taxablewinnings <= 189300:              
    rate4 = remainder3*0.28                                            
    remainder4 = taxablewinnings-189300                                

if taxablewinnings > 189300 and taxablewinnings <= 411500:             
    rate5 = remainder4*0.33                                            
    remainder5 = taxablewinnings-411500                                

if taxablewinnings > 411500 and taxablewinnings <= 413200:             
    rate6 = remainder5*0.33                                            
    remainder6 = taxablewinnings-413200                                

if taxablewinnings > 413200:                                           
    rate7 = remainder6*0.396                                           

else:                                                                  
    print("Invalid winnings input")                                    

if(winnings > 0):                                                          
    print("Your tax is: $%f" % tax)                                        

I am getting the error

rate3 = remainder2*0.25 NameError: name 'remainder2' is not defined

Aucun commentaire:

Enregistrer un commentaire