Difference between revisions of "CSC111 Homework 1 Solution"

From dftwiki3
Jump to: navigation, search
(Source Code)
(Source Code)
Line 20: Line 20:
 
def main ():
 
def main ():
 
     # *^*^*^*^*^ask user to provide all the information needed*^*^*^*^*^
 
     # *^*^*^*^*^ask user to provide all the information needed*^*^*^*^*^
     print ' '
+
     print  
 
     print 'Welcome!'
 
     print 'Welcome!'
     print ' '
+
     print  
 
     print 'This program will compute your taxes for 2009.'
 
     print 'This program will compute your taxes for 2009.'
     print ' '
+
     print  
 
     print 'You will be asked to enter some information. Please do NOT include'
 
     print 'You will be asked to enter some information. Please do NOT include'
 
     print '$ symbols or commas in your answers.'
 
     print '$ symbols or commas in your answers.'
     print ' '
+
     print  
 
     first      = raw_input('Please enter your first name: ')
 
     first      = raw_input('Please enter your first name: ')
 
     last      = raw_input('Please enter your last name: ')
 
     last      = raw_input('Please enter your last name: ')
Line 39: Line 39:
  
 
     # *^*^*^*^*^show results to user*^*^*^*^*^
 
     # *^*^*^*^*^show results to user*^*^*^*^*^
     print ' '
+
     print  
 
     print 'Dear', first, last+':'
 
     print 'Dear', first, last+':'
     print ' '
+
     print  
 
     print 'Your federal taxes for 2009 are:','$', federal
 
     print 'Your federal taxes for 2009 are:','$', federal
     print ' '
+
     print  
 
     print 'Your state taxes for 2009 are: ','$', state
 
     print 'Your state taxes for 2009 are: ','$', state
     print ' '
+
     print  
 
     print 'You will have to pay a total of', '$', total, 'in taxes.'
 
     print 'You will have to pay a total of', '$', total, 'in taxes.'
     print ' '
+
     print  
 
     print 'Thanks for using this program!'
 
     print 'Thanks for using this program!'
     print ' '
+
     print  
  
 
main ()
 
main ()

Revision as of 17:20, 9 February 2010

Source Code

# hw1.py
# Kristina Fedorenko 
# 111c-aq
#
# This program computes taxes for 2009
# based on user's salary and deductions. This information is
# entered by the user.
#
# To calculate the federal taxes the program 
# uses the following formula: (salary - deductions) x 28%
#
# The state taxes are computed using this formula:
# (salary - deductions - 1000) x 5%
#
#

def main ():
    # *^*^*^*^*^ask user to provide all the information needed*^*^*^*^*^
    print 
    print 'Welcome!'
    print 
    print 'This program will compute your taxes for 2009.'
    print 
    print 'You will be asked to enter some information. Please do NOT include'
    print '$ symbols or commas in your answers.'
    print 
    first      = raw_input('Please enter your first name: ')
    last       = raw_input('Please enter your last name: ')
    salary     = input('Please enter your salary for 2009: ')
    deductions = input('Please enter your deductions: ')

    # *^*^*^*^*^calculate federal and state taxes*^*^*^*^*^
    federal = (salary - deductions)*0.28
    state   = (salary - deductions -1000 )*0.05
    total   =  state + federal

    # *^*^*^*^*^show results to user*^*^*^*^*^
    print 
    print 'Dear', first, last+':'
    print 
    print 'Your federal taxes for 2009 are:','$', federal
    print 
    print 'Your state taxes for 2009 are: ','$', state
    print 
    print 'You will have to pay a total of', '$', total, 'in taxes.'
    print 
    print 'Thanks for using this program!'
    print 

main ()

Output

 
Welcome!
 
This program will compute your taxes for 2009.
 
You will be asked to enter some information. Please do NOT include
$ symbols or commas in your answers.
 
Please enter your first name: Sophia
Please enter your last name: Smith
Please enter your salary for 2009: 100000 
Please enter your deductions: 1000
 
Dear Sophia Smith:
 
Your federal taxes for 2009 are: $ 27720.0
 
Your state taxes for 2009 are:  $ 4900.0
 
You will have to pay a total of $ 32620.0 in taxes.
 
Thanks for using this program!