import sys # Recursive output of num_list {1{2{3 ... }}} def recursive_foo(num_list): if len(num_list) == 1: return '{' + num_list[0] + '}' else: return '{' + num_list[0] + recursive_foo(num_list[1:]) + '}' # Non Recursive output of num_list {1{2{3 ... }}} def non_recursive_foo(num_list): return '{' + '{'.join(num_list) + '}' * len(num_list) def main(): if len(sys.argv) < 2: print('The program ' + sys.argv[0] + ' should be run as: <path>/' + \ sys.argv[0] + ' <num>') return if sys.argv[1].isnumeric() and int(sys.argv[1]) > 0: num_list = [str(i) for i in range(1, int(sys.argv[1]) + 1)] print(recursive_foo(num_list)) print(non_recursive_foo(num_list)) else: print('The input data is wrong.', '<num> have to be positive integer') 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