Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Random832 Newsgroups: comp.lang.python Subject: Re: Just starting to learn Python, and encounter a problem Date: Fri, 22 Jul 2016 10:30:05 -0400 Lines: 31 Message-ID: References: <1469197805.1500560.673872225.0F14EA3D@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de ihh827sZvP6/gXYpBeG5sQ1jIC3NTMQGDkUWzYSWDCEg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'subject:Python': 0.05; '22,': 0.09; 'precedence': 0.09; 'received:internal': 0.09; 'yeah,': 0.09; '"michael': 0.16; '"or"': 0.16; '"write': 0.16; '(name': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'name",': 0.16; 'non- empty': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; '"you': 0.18; 'subject:problem': 0.22; 'header:In-Reply-To:1': 0.24; '(e.g.': 0.27; 'fri,': 0.27; 'asks': 0.29; 'tutorial': 0.29; 'becomes': 0.30; 'true.': 0.33; 'false': 0.35; 'quite': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'say': 0.37; 'received:66': 0.38; 'whatever': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'header:Message-Id:1': 0.61; 'here:': 0.63; 'said:': 0.66; 'jul': 0.72; 'leo': 0.84; 'subject:learn': 0.84; 'subject:Just': 0.91 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=/7LODX48hytXNDukRl93eeGSDDE=; b=aYKBgZ 6lAtGrh38GMXQwmGI2+qVbVR9n3K91BRMKdi7C9KAGsZPE8dQuzzG5L77PRMOoJ6 g0ZN0oPY+sTK08CJgtWHOwQbhdKlqgVPdBokrPZJYS3VyljyFsSLjJV7modUF4nQ m3cCG9S68y4/z+lrvQLC/K8UYC2zoQ9KxgaMc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=/7LODX48hytXNDu kRl93eeGSDDE=; b=ZkO6SZwDAHCY842aix5KL68Hktm3dWog3LC716Jmt6DkTau 2CBhxKfCmp2v6bdw0cLuAVSKXiOQpiKkkHJHi4q5d1xQOj1fC5fgfbCdHqOs1ee4 tgIP6YPEP+rz+Dj+ei9vyESgG9GP0UH+veQlbFmvOql7jqjxAUKJFwRv1mF0= X-Sasl-Enc: Cf4aHTgz3OzbGahzPMqaoLZEE1cics7IcT/XTdHbpSwk 1469197805 X-Mailer: MessagingEngine.com Webmail Interface - ajax-2ccfea0a In-Reply-To: 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: <1469197805.1500560.673872225.0F14EA3D@webmail.messagingengine.com> X-Mailman-Original-References: Xref: csiph.com comp.lang.python:111752 On Fri, Jul 22, 2016, at 09:59, 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. "or" is a lower precedence than "==". > if name == "John Cleese" or "Michael Palin" becomes if (name == "John Cleese") or "Michael Palin"; becomes if False or "Michael Palin"; becomes if "Michael Palin"; and non-empty strings are considered true. You want if Name == "John Cleese" or Name == "Michael Palin"; or if Name in ("John Cleese", "Michael Palin")