Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #111758

Re: Just starting to learn Python, and encounter a problem

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From MRAB <python@mrabarnett.plus.com>
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 <mailman.54.1469200100.22221.python-list@python.org> (permalink)
References <ac35006b-ab2e-44f1-b896-cd57d9689c73@googlegroups.com> <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 <python@mrabarnett.plus.com>
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 <ac35006b-ab2e-44f1-b896-cd57d9689c73@googlegroups.com>
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 <685410d4-3db5-68ed-50c3-3a0d2646fbce@mrabarnett.plus.com>
X-Mailman-Original-References <ac35006b-ab2e-44f1-b896-cd57d9689c73@googlegroups.com>
Xref csiph.com comp.lang.python:111758

Show key headers only | View raw


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!)

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


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