#!/usr/bin/python NEWLINE = '\n' def main(): print head('greet',35) print greet('google'),NEWLINE,greet('python'),NEWLINE,greet('Guido'),NEWLINE print head('repeat',35) print repeat('hello ', False),NEWLINE,repeat('goodbye ', True) # Defines a "head" function that takes 1 argument. def head(func,length): """Returns a '-' repeated n times""" return 'Calling the "X" function'.replace('X',func) + NEWLINE + '-' * length # Defines a "greet" function that takes 1 argument. def greet(user): """Returns a hello there plus user""" return 'hello there X'.replace('X',user) # Defines a "repeat" function that takes 2 arguments. def repeat(target, exclaim): """Returns the target string repeated 3 times. If exclaim is true, add exclamation marks. """ result = target * 3 if exclaim: result = result + '!!!' return result # Standard boilerplate to call the main() function to begin the program. if __name__ == '__main__': main()
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