Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64736
| Date | 2014-01-25 11:24 +0100 |
|---|---|
| From | Ervin Hegedüs <airween@gmail.com> |
| Subject | Re: Help with my 8-year old son's first program. I'm stuck! |
| References | <453f851d-815d-4bdd-b591-71cafc95084f@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5971.1390645712.18130.python-list@python.org> (permalink) |
Hello,
On Sat, Jan 25, 2014 at 02:02:15AM -0800, justinpmullins@gmail.com wrote:
> My son is learning Python and I know nothing about computers.
:)
> He's written a simple calculator program that doesn't work. For the life of me, I can't see why.
> Any help gratefully received. Here's his code:
> 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")
>
> Where is he going wrong?
what's your error message?
First, you have to put an interpreter in first line - if you're
on Linux/Unix:
#!/usr/bin/python
or some kind of that. I don't know what's the expected on Windows
:(.
Second, you defined a funcfion, called "a", and if you want to
see how does it work, you must call that (after you define it):
def a():
...
...
a()
Third, at the first statement (if op == str(d)) you're
referencing for an undefined variable (d), I think you would
put `if op == "d":', instad of that.
Good luck,
Ervin
--
I � UTF-8
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Help with my 8-year old son's first program. I'm stuck! justinpmullins@gmail.com - 2014-01-25 02:02 -0800
Re: Help with my 8-year old son's first program. I'm stuck! Ervin Hegedüs <airween@gmail.com> - 2014-01-25 11:24 +0100
Re: Help with my 8-year old son's first program. I'm stuck! justinpmullins@gmail.com - 2014-01-25 02:32 -0800
Re: Help with my 8-year old son's first program. I'm stuck! Peter Otten <__peter__@web.de> - 2014-01-25 11:41 +0100
Re: Help with my 8-year old son's first program. I'm stuck! justinpmullins@gmail.com - 2014-01-25 07:58 -0800
Re: Help with my 8-year old son's first program. I'm stuck! Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-25 11:35 +0000
csiph-web