Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: MRAB Newsgroups: comp.lang.python Subject: Re: Just starting to learn Python, and encounter a problem Date: Fri, 22 Jul 2016 16:08:17 +0100 Lines: 43 Message-ID: References: <685410d4-3db5-68ed-50c3-3a0d2646fbce@mrabarnett.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de sTbnlV9HdwbG6gU/N41oiQ5QzlzGCa+X/IVFL/w89+lQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'subject:Python': 0.05; 'alternatives': 0.09; 'yeah,': 0.09; '"michael': 0.16; '"santa': 0.16; '"write': 0.16; '(name': 0.16; 'available;': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'name",': 0.16; 'received:192.168.1.4': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'string': 0.17; '"you': 0.18; 'subject:problem': 0.22; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; '(e.g.': 0.27; 'asks': 0.29; 'be:': 0.29; 'tutorial': 0.29; 'true.': 0.33; 'except': 0.34; 'false': 0.35; 'quite': 0.35; 'but': 0.36; 'should': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'means': 0.39; 'whatever': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; "you'll": 0.61; 'here:': 0.63; 'said:': 0.66; 'as:': 0.79; 'leo': 0.84; 'subject:learn': 0.84; 'subject:Just': 0.91 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.2 cv=dMLko6Rb c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=IkcTkHD0fZMA:10 a=RyhsMTB_H5-UGAwm2-gA:9 X-AUTH: mrabarnett@:2500 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 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: <685410d4-3db5-68ed-50c3-3a0d2646fbce@mrabarnett.plus.com> X-Mailman-Original-References: Xref: csiph.com comp.lang.python:111758 On 2016-07-22 14: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. > This bit: name == "John Cleese" or "Michael Palin" means the same as: (name == "John Cleese") or "Michael Palin" If name is "Santa Claus", that's: "Santa Claus" == "John Cleese" or "Michael Palin" which is: False or "Michael Palin" which is: "Michael Palin" and any string except "" is treated as True. The condition should be: name == "John Cleese" or name == "Michael Palin" (Shorter alternatives are available; you'll learn about them later!)