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


Groups > comp.lang.python > #52277

Re: beginner question (True False help)

References <6c6dedec-5e47-4229-bc67-01b058cdb410@googlegroups.com> <b9e1881e-dd26-497f-83d0-8884d08ec8ff@googlegroups.com>
From Joshua Landau <joshua@landau.ws>
Date 2013-08-10 00:05 +0100
Subject Re: beginner question (True False help)
Newsgroups comp.lang.python
Message-ID <mailman.410.1376089560.1251.python-list@python.org> (permalink)

Show all headers | View raw


On 9 August 2013 23:27,  <eschneider92@comcast.net> wrote:
> This is what I ended up with btw. Does this insult anyone's more well attuned Python sensibilities?

...

Yes.

You didn't listen to any of the advice we've been giving you. You've
had *much* better answers given than this.


Start from the top.

We need letters, so define that:

    letters = "abcdefghijkl"

We then want to loop, possibly forever. A good choice is a "while" loop.

    # True is always True, so will loop forever
    while True:

We then want to ask for a letter. We want to use "input". Write
"help(input)" in the Python Shell and you get

    >>> help(input)
    Help on built-in function input in module builtins:

    input(...)
        input([prompt]) -> string

        Read a string from standard input.  The trailing newline is stripped.
        If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return),
raise EOFError.
        On Unix, GNU readline is used if enabled.  The prompt string, if given,
        is printed without a trailing newline before reading.

So our line should be:

    letter = input("Type a letter from 'a' to 'n' in the alphabet: ")

Then we want to test if it's on of our letters:

    if letter in letters:

And if so we want to say something positive:

        print("That's right.")

If not we want to say something negative:

    else:
        print("That's wrong.")

And then we want to ask if we should go again:

    go_again = input("Do you want to do this again? ")

If the response is "y" or "yes", we want to continue looping. The
while loop will do that automatically, so we can do nothing in this
circumstance.

If the response in *not* "y" or "yes", we want to stop:

    if go_again not in ("y", "yes"):
       break


That's it. No need to complicate things. Just take it one step at a time.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

beginner question (True False help) eschneider92@comcast.net - 2013-08-07 01:17 -0700
  Re: beginner question (True False help) Joshua Landau <joshua@landau.ws> - 2013-08-07 09:42 +0100
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-07 13:59 -0700
    Re: beginner question (True False help) Dave Angel <davea@davea.name> - 2013-08-08 01:18 +0000
  Re: beginner question (True False help) Larry Hudson <orgnut@yahoo.com> - 2013-08-07 19:49 -0700
  Re: beginner question (True False help) wxjmfauth@gmail.com - 2013-08-07 23:20 -0700
    Re: beginner question (True False help) Chris Angelico <rosuav@gmail.com> - 2013-08-08 12:41 +0100
    Re: beginner question (True False help) Terry Reedy <tjreedy@udel.edu> - 2013-08-08 16:29 -0400
      Re: beginner question (True False help) wxjmfauth@gmail.com - 2013-08-09 01:05 -0700
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 15:27 -0700
    Re: beginner question (True False help) Joshua Landau <joshua@landau.ws> - 2013-08-10 00:05 +0100
    Re: beginner question (True False help) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-08-09 22:58 -0400
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 15:28 -0700
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:14 -0700
    Re: beginner question (True False help) Joshua Landau <joshua@landau.ws> - 2013-08-10 00:30 +0100
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:24 -0700
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:34 -0700
    Re: beginner question (True False help) Joshua Landau <joshua@landau.ws> - 2013-08-10 02:22 +0100
    Re: beginner question (True False help) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-10 01:40 +0000
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:40 -0700
    Re: beginner question (True False help) MRAB <python@mrabarnett.plus.com> - 2013-08-10 01:39 +0100
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:43 -0700
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 18:08 -0700

csiph-web