Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Bob Gailer 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: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de wGBffTADLUCnR1hO5D76rQ+QMd8xDLLeKgJu0zQCHGnw== Return-Path: 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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: Xref: csiph.com comp.lang.python:111753 On Jul 22, 2016 10:00 AM, "Zagyen Leo" 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"):