Help with my 8-year old son's first program. I'm stuck!

Denis McMahon denismfmcmahon at gmail.com
Sat Jan 25 06:35:00 EST 2014


On Sat, 25 Jan 2014 02:02:15 -0800, justinpmullins wrote:

> def a():
> 	import sys print("welcome to the calculation") print("please type 
a
> 	number")
> 	one = int(sys.stdin.readline()) print("type d for division,")
> 	print("type m for multiplication,") print("type s for 
subtraction,")
> 	print("and type p for plus")
> 	op = (sys.stdin.readline()) print("%s selected" % op) print
("please
> 	enter another number")
> 	two = int(sys.stdin.readline())
> 	if op == str(d):
> 		out == one / two print("the answer is %s" % out)
> 	elif op == "m":
> 		out == one * two print("the answer is %s" % out)
> 	elif op == "s":
> 		out == one - two print("the answer is %s" % out)
> 	elif op == "p":
> 		out == one + two print("the answer is %s" % out)
> 	else:
> 		print("huh")

a() is a function, but I can see nothing in the code that invokes the 
function a()

Ignore the comment about needing to define the type of file on the first 
line on linux, it's a red herring. You only need to do that (and possibly 
chmod the file) on a *nix system if you want to execute it directly as a 
command, rather than by calling the interpreter on it.

I suspect that if you remove the line:

"def a():"

and un-indent the rest of the text, the program will run just fine.

-- 
Denis McMahon, denismfmcmahon at gmail.com



More information about the Python-list mailing list