Welcome, guest | Sign In | My Account | Store | Cart

Here is a very simple program in Python to multiply 2 numbers. I worte for my blog Captain DeadBones Chronicles

Python, 14 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import sys

def main(argv):

	if len(argv) != 2:
		sys.exit('Usage: simple_multi.py <a> <b>')
		
	a = int(sys.argv[1])
	b = int(sys.argv[2])
		
	print "The result of " + str(a) + " times " + str(b) + " is: " + str(a*b)

if __name__ == "__main__":
	main(sys.argv[1:])

3 comments

Dan Zemke 8 years, 5 months ago  # | flag

IMO, the author is abusing this code repository and the community that uses it. Polluting it with useless trivia meant solely for his personal blog.

Please stop.

Captain DeadBones (author) 8 years, 5 months ago  # | flag

Dan,

I am sorry to hear you feel like that. I do admit the codes I post are taken from longer posts on my personal blog. I am not trying to hide it by any means. However, I do not pollute or abuse the repository and the community by any means. If I do, than I apologize. My mission is that of education, not mischief. This code in particular has a lot of elements that could teach beginners about coding, particular in Python. Just to mention a few, the program uses arguments passed in via command line, functions, import, string casting, variable assignments and other key ideas new programmers should learn. I was under the impersonation that the community would like to share and grow, not turn away people. Code is code, simple or complex, everyone can learn from anything. If you wish, I can post some of the more complex things I have done. If you are to notice, I did post a text editor I wrote in python that has no relation to any of my current posts. I do not have any intention to stop posting code here on anywhere else I wish to. If you have any issues with any of that, you can feel free to contact me here or via email: cpt_at_thelivingpearl.com .

Have a nice day.

Captain DeadBones

Dan Zemke 8 years, 5 months ago  # | flag

Captain DeadBones, I apologise for the style of my curt note above.

Educating is a wonderful mission. But I suspect you wouldn't try to educate folks about Python concepts during a cardiopulmonary resuscitation class, or an on-line discussion about religion. Context matters. Most communities have a focus, and stuff that is far away from that just adds noise. IMO, a good way to assess the desired focus of this Python community is to peruse the "Top-rated recipes". The list rates submissions from highest to lowest. The top-rated recipe list is at http://code.activestate.com/recipes/top/

You won't find any of the highest rated recipes addressing beginning concepts like how to pass a command line argument or casting a string.

"Code is code, simple or complex, everyone can learn from anything." Yes, but if all conversations on every subject get dumped into the same thread, everyone loses because most of the posts are noise to each person, regardless of their focus or background. That why groups become specialized, or have subsections that are specialized.

I thought your text editor was a good recipe that could be reused and tailored to specific needs. That's why I and others bumped up its rating.

Please rethink posting basic concepts here. Beginners don't generally come here (your referrals don't count :-)),

Dan