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, 18 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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])
	sum = 0
	
	for i in range(a):
		sum += b
		
	print "The result of " + str(a) + " times " + str(b) + " is: " + str(sum)

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