Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43199
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@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; 'string.': 0.05; 'explicit': 0.07; 'lately': 0.07; 'strict': 0.07; 'subject:help': 0.08; 'string': 0.09; 'expression:': 0.09; 'false,': 0.09; 'false.': 0.09; 'integers': 0.09; 'main()': 0.09; 'matched': 0.09; 'restart': 0.09; 'statements': 0.09; 'works.': 0.09; 'python': 0.11; '2.7.2': 0.16; 'bool': 0.16; 'boolean': 0.16; 'brackets.': 0.16; 'colons,': 0.16; 'does,': 0.16; 'fine.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'indent': 0.16; 'instance:': 0.16; 'normally,': 0.16; 'optional.': 0.16; 'perfect.': 0.16; 'statement.': 0.16; 'syntax,': 0.16; 'true:': 0.16; 'worse.': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'code.': 0.18; 'wed,': 0.18; 'print': 0.22; 'instance,': 0.24; 'logical': 0.24; "shouldn't": 0.24; 'java': 0.24; "i've": 0.25; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'matching': 0.30; 'said,': 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; 'lines': 0.31; 'too.': 0.31; '4.0': 0.31; 'argue': 0.31; 'comments,': 0.31; 'indentation': 0.31; 'lists': 0.32; 'compatible': 0.32; 'checking': 0.33; 'actual': 0.34; 'could': 0.34; 'message.': 0.35; 'something': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'version': 0.36; 'c++': 0.36; 'false': 0.36; 'doing': 0.36; "didn't": 0.36; 'method': 0.36; 'two': 0.37; 'list': 0.37; 'level': 0.37; 'sometimes': 0.38; 'apple': 0.38; 'depends': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'that,': 0.38; 'structure': 0.39; 'delete': 0.39; 'to:addr:python.org': 0.39; 'according': 0.40; 'how': 0.40; 'even': 0.60; 'catch': 0.60; 'helps': 0.61; "you're": 0.61; 'first': 0.61; 'back': 0.62; 'times': 0.62; "you'll": 0.62; 'making': 0.63; 'information': 0.63; 'more': 0.64; 'levels': 0.65; 'it!': 0.67; 'legal': 0.71; 'friendly': 0.72; 'physical': 0.72; '4.2.1': 0.84; 'imagine': 0.93; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type:content-transfer-encoding; bh=pokEkhLRhf/zwGg1CYCVdMQ8Xvs0tCFeg8L63//2al0=; b=y5nZ4Dyoq4tXqnX8vSt6kyfn9tj1nPuiXQa2/2j6t7yiUE7DWnEx2jZ6ZIUehkhow6 8bFcBUVfF1g/nB+TMsDlfc+9PMmznHH1WRkdQYo517T+GB0p7Xk52g92w5T08dm1EC8U DoSNiDZnta9Fe8ZD0GKHuIEMx7X04ATu/lJl/YNsrxmZA0KqdcUVWfmHK4naSgKh/e0r 4hSKuLWJWFkMabcVdbuW33fHKq1DK6kiA/C4R/mMYhVPJW8af74mB7uRq36evaKZaG6W K/rTZUJsLP+gnDgXrPXE+9/thbhVaH0jUCTRndWgRnERHQrj06Q4Mg/EXgofKDZ0aj0Y Ve+Q== |
| MIME-Version | 1.0 |
| X-Received | by 10.52.91.71 with SMTP id cc7mr2138779vdb.58.1365526025080; Tue, 09 Apr 2013 09:47:05 -0700 (PDT) |
| In-Reply-To | <1629a072-c512-439c-b751-c44f8e945c2e@googlegroups.com> |
| References | <b93147e7-9d17-4232-99a3-767b88f9e9ba@googlegroups.com> <596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com> <mailman.348.1365516328.3114.python-list@python.org> <a530b25f-f9d9-45e9-925c-0ecd8a660cf6@googlegroups.com> <mailman.359.1365523839.3114.python-list@python.org> <1629a072-c512-439c-b751-c44f8e945c2e@googlegroups.com> |
| Date | Wed, 10 Apr 2013 02:47:05 +1000 |
| Subject | Re: While loop help |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| 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 | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.366.1365526028.3114.python-list@python.org> (permalink) |
| Lines | 101 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1365526028 news.xs4all.nl 2634 [2001:888:2000:d::a6]:45466 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:43199 |
Show key headers only | View raw
On Wed, Apr 10, 2013 at 2:24 AM, <thomasancilleri@gmail.com> wrote:
> For system version I get this:
> 2.7.2 (default, Oct 11 2012, 20:14:37)
> [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]
Lovely! Perfect.
> But, what I don't understand exactly is the while statement. I've been looking around a lot lately and notice that people say to use for instance:
>
> while restart: or while true: or while restart = true:
while x:
y
will check whether x "feels trueish", and if it does, will execute y,
then go back and check x again. The general principle is that
something is true and nothing is false - for instance, 0 and 0.0 are
false, while 42 and 0.143 are true. Same goes for lists and such; an
empty list is false, a list with something in it is true.
When you make an actual comparison, you'll get back a result that,
normally, will be one of the strict bool objects True and False. For
instance, the expression:
restart == "true"
will be True if restart has the string "true", and False if it has any
other string.
> What makes a statement true? Is there a way to return a true or false message. My method was to ask the user to type "true" and if that print statement matched restart = "true" then the loop would continue but i imagine there is a better way then matching strings and integers like i have been.
You can print anything, even the boolean values! :) Try it!
Your method works fine. Since you're getting something with
raw_input(), you're working with strings; whatever the user enters,
that's what you work with. You could make it more friendly by checking
just the first letter and case insensitively, and making it "Continue?
Y/N", but that's optional.
> Also what confuses me is that python doesn't use brackets. How do I contain all of my if/else statements into one while loop? Do I have to indent each line of code and extra indentation? I'm used to highschool doing c++ and java when I would just say:
>
> while (x<3)
> {
> if ()
> else ()
> }
It's conventional in C++ to indent every block of code.
int main()
{
//Indent one level
initialize()
while (...)
{
//Indent two levels
do_stuff()
if (...)
{
//Indent three levels
do_more_stuff()
}
do_less_stuff()
}
close_all()
}
Now, just delete all those lines with nothing but braces. You can
still see the program's logical structure:
int main()
//Indent one level
initialize()
while (...)
//Indent two levels
do_stuff()
if (...)
//Indent three levels
do_more_stuff()
do_less_stuff()
close_all()
This is how Python works. (And it's almost legal Python syntax, too.
Add a few colons, fix the comments, pretty much done.) For better or
for worse, Python depends on the indentation; but 99%+ of the time,
you would have that indentation even if it didn't matter. (Personally,
I prefer explicit braces. The duplicated information at times helps
catch bugs, and sometimes I format code according to a logical
structure that doesn't necessarily match its physical structure. It's
a freedom I don't often make use of, but it's one that Python denies
me... as I said, for better or for worse. There are those who argue
that that's a freedom I shouldn't have.)
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
While loop help thomasancilleri@gmail.com - 2013-04-09 06:32 -0700
Re: While loop help thomasancilleri@gmail.com - 2013-04-09 06:57 -0700
Re: While loop help Dave Angel <davea@davea.name> - 2013-04-09 13:12 -0400
Re: While loop help thomasancilleri@gmail.com - 2013-04-09 10:18 -0700
Re: While loop help Chris Angelico <rosuav@gmail.com> - 2013-04-10 03:23 +1000
Re: While loop help Dave Angel <davea@davea.name> - 2013-04-09 13:30 -0400
Re: While loop help thomasancilleri@gmail.com - 2013-04-09 06:58 -0700
Re: While loop help Chris Angelico <rosuav@gmail.com> - 2013-04-10 00:05 +1000
Re: While loop help thomasancilleri@gmail.com - 2013-04-09 08:47 -0700
Re: While loop help Joel Goldstick <joel.goldstick@gmail.com> - 2013-04-09 12:02 -0400
Re: While loop help Chris Angelico <rosuav@gmail.com> - 2013-04-10 02:10 +1000
Re: While loop help thomasancilleri@gmail.com - 2013-04-09 09:24 -0700
Re: While loop help Joel Goldstick <joel.goldstick@gmail.com> - 2013-04-09 12:36 -0400
Re: While loop help Chris Angelico <rosuav@gmail.com> - 2013-04-10 02:47 +1000
Re: While loop help thomasancilleri@gmail.com - 2013-04-09 09:57 -0700
Re: While loop help Chris Angelico <rosuav@gmail.com> - 2013-04-10 03:08 +1000
Re: While loop help Dave Angel <davea@davea.name> - 2013-04-09 13:27 -0400
Re: While loop help thomasancilleri@gmail.com - 2013-04-09 09:57 -0700
Re: While loop help thomasancilleri@gmail.com - 2013-04-09 09:24 -0700
Re: While loop help Walter Hurry <walterhurry@lavabit.com> - 2013-04-09 19:35 +0000
Re: While loop help Dave Angel <davea@davea.name> - 2013-04-09 16:12 -0400
Re: While loop help Walter Hurry <walterhurry@lavabit.com> - 2013-04-09 20:59 +0000
Re: While loop help Chris Angelico <rosuav@gmail.com> - 2013-04-10 08:36 +1000
Re: While loop help rusi <rustompmody@gmail.com> - 2013-04-10 08:59 -0700
Re: While loop help thomasancilleri@gmail.com - 2013-04-09 08:47 -0700
Re: While loop help Chris Angelico <rosuav@gmail.com> - 2013-04-10 00:00 +1000
Re: While loop help thomasancilleri@gmail.com - 2013-04-09 09:49 -0700
Re: While loop help Larry Hudson <orgnut@yahoo.com> - 2013-04-09 23:44 -0700
Re: While loop help Larry Hudson <orgnut@yahoo.com> - 2013-04-10 20:00 -0700
Re: While loop help jmfauth <wxjmfauth@gmail.com> - 2013-04-09 12:19 -0700
csiph-web