# Program: Tax and Tip Calculator # Last Modified: Thursday, December 15th, 2016 # PSEUDOCODE # Ask user if tip value should be calculated before or after tax [0 or 1] # Ask user for the cost # Ask user for tax percentage # Ask user for tip percentage # Return cost multiplied by tax percentage # If 0 # Return cost of multiplied by tip percentage for tip # If 1 # Return cost + cost of tax multiplied by tip percentage for tip # CODE: print # Tax calculator function def taxCalc (cost, percentageTax): return (cost * (percentageTax / 100)); # END OF TAX CALCULATOR FUNCTION def tipCalc (cost, percentageTip): return (cost * (percentageTip / 100)); # END OF TIP CALCULATOR FUNCTION # Ask user if tip value should be calculated before or after tax [0 or 1] print ("Should the tip be calculated before [0], or after tax [1]? \n"); tipSetting = int(raw_input()); # Ask user for the cost print ("Enter in the cost before tax and without a $ sign: \n"); cost = float(raw_input()); # Ask user for tax percentage print ("Enter in the TAX percentage as a whole number (i.e., 13% = 13) \n"); percentageTax = int(raw_input()); # Ask user for tip percentage print ("Enter in the TIP percentage as a whole number (i.e., 13% = 13) \n"); percentageTip = int(raw_input()); # Return cost multiplied by tax percentage costWithTax = taxCalc (cost, percentageTax); print ("The cost with tax is: $" + str(costWithTax)); # If 0 if (tipSetting == 0): # Return cost multiplied by tip percentage for tip costOfTip = taxCalc (cost, percentageTip); print ("The cost of the tip calculated before tax is: $" + str(costOfTip)); # Else if 1 elif (tipSetting == 1): # Return cost + cost of tax multiplied by tip percentage for tip costOfTip = taxCalc (costWithTax, percentageTip); print ("The cost of the tip calculated after tax is: $" + str(costOfTip));
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question