Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64736

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

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <airween@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'elif': 0.05; 'interpreter': 0.05; 'sys': 0.07; 'utf-8': 0.07; '%s"': 0.09; 'undefined': 0.09; 'cc:addr:python-list': 0.11; 'subject:Help': 0.11; 'python': 0.11; 'def': 0.12; 'jan': 0.12; 'windows': 0.15; '(d),': 0.16; 'a()': 0.16; 'a():': 0.16; 'calculator': 0.16; 'luck,': 0.16; 'out)': 0.16; 'referencing': 0.16; 'subject:son': 0.16; 'subject:stuck': 0.16; 'third,': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'work,': 0.20; 'written': 0.21; 'import': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'why.': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'define': 0.26; 'first,': 0.26; 'code:': 0.26; 'defined': 0.27; 'header:In-Reply- To:1': 0.27; "doesn't": 0.30; 'statement': 0.30; 'skip:( 20': 0.30; 'work.': 0.31; 'that.': 0.31; '25,': 0.31; 'second,': 0.31; 'another': 0.32; 'skip:# 10': 0.33; 'subject:with': 0.35; "can't": 0.35; 'received:84': 0.35; "he's": 0.36; 'two': 0.37; 'expected': 0.38; 'does': 0.39; 'called': 0.40; 'how': 0.40; 'son': 0.61; 'from:charset:utf-8': 0.61; 'simple': 0.61; "you're": 0.61; 'first': 0.61; 'content-disposition:inline': 0.62; 'email addr:gmail.com': 0.63; 'kind': 0.63; 'to:addr:gmail.com': 0.65; 'life': 0.66; 'subject:. ': 0.67; 'computers.': 0.84; 'received:hu': 0.93
X-Spam-Flag NO
X-Spam-Score -1.998
X-Spam-Level
X-Spam-Status No, score=-1.998 tagged_above=-20 required=4 tests=[ALL_TRUSTED=-1, BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, NML_ADSP_CUSTOM_MED=0.9] autolearn=no
Date Sat, 25 Jan 2014 11:24:33 +0100
From Ervin Hegedüs <airween@gmail.com>
To justinpmullins@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>
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Disposition inline
Content-Transfer-Encoding 8bit
In-Reply-To <453f851d-815d-4bdd-b591-71cafc95084f@googlegroups.com>
User-Agent Mutt/1.5.20 (2009-06-14)
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5971.1390645712.18130.python-list@python.org> (permalink)
Lines 71
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1390645712 news.xs4all.nl 2971 [2001:888:2000:d::a6]:56996
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:64736

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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