Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #111753
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Bob Gailer <bgailer@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Just starting to learn Python, and encounter a problem |
| Date | Fri, 22 Jul 2016 10:36:25 -0400 |
| Lines | 36 |
| Message-ID | <mailman.50.1469198194.22221.python-list@python.org> (permalink) |
| References | <ac35006b-ab2e-44f1-b896-cd57d9689c73@googlegroups.com> <CAP1rxO6F0q2dOd1T_wV0=PNN6Gny1wFDQ3GUw5Js-7pTaEwREQ@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de wGBffTADLUCnR1hO5D76rQ+QMd8xDLLeKgJu0zQCHGnw== |
| Return-Path | <bgailer@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'operator': 0.03; 'subject:Python': 0.05; 'false.': 0.07; 'cc:addr:python- list': 0.09; '")': 0.09; '22,': 0.09; 'yeah,': 0.09; '"michael': 0.16; '"write': 0.16; '(name': 0.16; '10:00': 0.16; '2016': 0.16; 'cc:name:python list': 0.16; 'evaluates': 0.16; 'name",': 0.16; 'received:io': 0.16; 'received:mail- qk0-x236.google.com': 0.16; 'received:psf.io': 0.16; 'which,': 0.16; 'wrote:': 0.16; '"you': 0.18; '>': 0.18; 'email addr:gmail.com>': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'subject:problem': 0.22; 'am,': 0.23; 'header:In-Reply- To:1': 0.24; '(e.g.': 0.27; 'message-id:@mail.gmail.com': 0.27; '"': 0.29; 'asks': 0.29; 'tutorial': 0.29; 'michael': 0.33; 'true.': 0.33; 'received:google.com': 0.35; 'false': 0.35; 'quite': 0.35; 'but': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'say': 0.37; 'whatever': 0.39; 'your': 0.60; 'here:': 0.63; 'believe': 0.66; 'said:': 0.66; 'results': 0.66; 'jul': 0.72; 'as:': 0.79; 'not)': 0.84; 'or:': 0.84; 'subject:learn': 0.84; 'want:': 0.84; 'subject:Just': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=2FByW3hl0tS5WESDvcdNXfMqEFnlPurvkApfXdv83fw=; b=rn/xZhjGvKc1twWobEqYSlKvZVJDmvfn3BExmBTPVZoPiaRFuywFBWdK4R9BYvDACP ZpXhvZ1ocfztppsNjQXPHM8raIlMJ0c4+CnblzV2IbSKM8OcJO3Ka5l+SzFNDrVUT929 jpQChsx7nbTv3uUutd4NkAjf7cPOX/BMy3XnQSZrHqpfzgueh/HcbXSSPZOvUgaexuuy fv4D43gG5k1+sOieitMHLyu3P6t0smtlUolSgntxdcS5CBLXHjTXGN92oOExv59HfL+R rR7oyddlfJHKOyTIm4Ol0Kkdez52twyH7P7jD90U9xpHj+JDcAZ7NENJMhDNRHysNwuT 3A4g== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=2FByW3hl0tS5WESDvcdNXfMqEFnlPurvkApfXdv83fw=; b=L8K28MkV+z7L9qTideijq5OuDZdQ69Y4DWGkdmMYwBHlJuLZvtEg5S7kHxN6PmFSRl r0MsLUnNi47JfgI6hqsqWGctF4hbTanu1+wOZJnr7lYvnDjlU/+HAfiLNBGnVWHLBfPc zjo/4n2GCc7o3DWjJdvDxlaYs5QwPpyxAWoDi4J7klBiLKOkia6f4ucFGsI9Jjpw2IkN LPo+S+0Ze/BoiuVk3NDeCrYpIOZ8U/7FRP+otUlhbvR8RVPl3nmqB71/1BZhPazJ8GZy OYwyXHe73S3x6PSj1jD/wUf4D0gofFoNOQAcHGDb13lFbATh/rl3+HKGiNfUTTl4R/Al XVtQ== |
| X-Gm-Message-State | AEkoous/VKyi2kQ7agUGuqI2tcKrSqusjW0PekTfz5I/u/QwIRymYqLZhflUibASqqoNTmzLyxU5k6CDGUSFlg== |
| X-Received | by 10.55.142.66 with SMTP id q63mr4680262qkd.98.1469198185719; Fri, 22 Jul 2016 07:36:25 -0700 (PDT) |
| In-Reply-To | <ac35006b-ab2e-44f1-b896-cd57d9689c73@googlegroups.com> |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.22 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| 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> |
| X-Mailman-Original-Message-ID | <CAP1rxO6F0q2dOd1T_wV0=PNN6Gny1wFDQ3GUw5Js-7pTaEwREQ@mail.gmail.com> |
| X-Mailman-Original-References | <ac35006b-ab2e-44f1-b896-cd57d9689c73@googlegroups.com> |
| Xref | csiph.com comp.lang.python:111753 |
Show key headers only | View raw
On Jul 22, 2016 10:00 AM, "Zagyen Leo" <zagyen@gmail.com> wrote:
>
> yeah, it may be quite simple to you experts, but hard to me.
>
> In one of exercises from the Tutorial it said: "Write a program that asks
the user their name, if they enter your name say "That is a nice name", if
they enter "John Cleese" or "Michael Palin", tell them how you feel about
them ;), otherwise tell them "You have a nice name."
>
> And i write so:
>
> name = input("Enter your name here: ")
> if name == "John Cleese" or "Michael Palin":
> print("Sounds like a gentleman.")
> else:
> print("You have a nice name.")
>
> But strangely whatever I type in (e.g. Santa Claus), it always say
"Sounds like a gentleman.", not the result I want.
Even without knowing the operator precedence, this will be evaluated either
as:
(name == "John Cleese") or "Michael Palin")
or:
name == ("John Cleese" or "Michael Palin").
Case 1: (name == "John Cleese") evaluates to either True or False. False
or "Michael Palin" evaluates to ( believe it or not) " Michael Palin"!
Which, as far as if is concerned, is True. True or "Michael Palin"
evaluates to True.
Case 2: "John Cleese" or "Michael Palin" evaluates to False; name== False
evaluates to False.
One way to get the results you want:
if name in ("John Cleese" or "Michael Palin"):
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Just starting to learn Python, and encounter a problem Zagyen Leo <zagyen@gmail.com> - 2016-07-22 06:59 -0700
Re: Just starting to learn Python, and encounter a problem Random832 <random832@fastmail.com> - 2016-07-22 10:30 -0400
Re: Just starting to learn Python, and encounter a problem Zagyen Leo <zagyen@gmail.com> - 2016-07-22 23:13 -0700
Re: Just starting to learn Python, and encounter a problem Bob Gailer <bgailer@gmail.com> - 2016-07-22 10:36 -0400
Re: Just starting to learn Python, and encounter a problem gst <g.starck@gmail.com> - 2016-07-23 11:18 -0700
Re: Just starting to learn Python, and encounter a problem MRAB <python@mrabarnett.plus.com> - 2016-07-23 20:06 +0100
Re: Just starting to learn Python, and encounter a problem Steven D'Aprano <steve@pearwood.info> - 2016-07-24 11:58 +1000
Re: Just starting to learn Python, and encounter a problem Gordon Levi <gordon@address.invalid> - 2016-07-23 00:37 +1000
Re: Just starting to learn Python, and encounter a problem justin walters <walters.justin01@gmail.com> - 2016-07-22 08:04 -0700
Re: Just starting to learn Python, and encounter a problem MRAB <python@mrabarnett.plus.com> - 2016-07-22 16:08 +0100
csiph-web