# absoluteValue: number -> number # return the absolute value of the input number def absoluteValue(x): if x < 0: return -x else: return x # isLeapYear: int -> boolean # return true if the given integer is the year number of a leap year def isLeapYear(year): if year % 100 == 0: return year % 400 == 0 else: return year % 4 == 0 # singlesAmountTaxed: float -> float # return the amount of income taxed for an umarried US citizen in 2013 def singlesAmountTaxed(salary): if salary <= 8925: rate = 0.1 elif salary <= 36250: rate = 0.15 elif salary <= 87850: rate = 0.25 elif salary <= 183250: rate = 0.28 elif salary <= 398350: rate = 0.33 elif salary <= 400000: rate = .35 else: rate = 0.396 return salary * rate # frogToPrince: string -> string # replace all instances of the word 'frog' with the word 'prince' and if none occur # return a silly message. def frogToPrince(myString): if 'frog' in myString: return myString.replace('frog', 'prince') else: return 'My kingdom for a frog!' # domainName: string -> string # return the domain name of an email address, or the empty string by default. def domainName(myString): if '@' in myString: beginning = myString.find('@') return myString[beginning + 1:] else: return '' print absoluteValue(-7) print isLeapYear(2004) print singlesAmountTaxed(394785) print frogToPrince('My frog is a prince!') print domainName("jkun2@uic.edu")
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