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


Groups > comp.lang.python > #111757

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

From justin walters <walters.justin01@gmail.com>
Newsgroups comp.lang.python
Subject Re: Just starting to learn Python, and encounter a problem
Date 2016-07-22 08:04 -0700
Message-ID <mailman.53.1469199887.22221.python-list@python.org> (permalink)
References <ac35006b-ab2e-44f1-b896-cd57d9689c73@googlegroups.com> <iva4pb9nc50pa8tdca5mak6fnt3fvj5lc1@4ax.com> <CAO1D73EdFVia=qPQm1TY97ouUifnK_WuA6HeA0wRxHvX2nHDOg@mail.gmail.com>

Show all headers | View raw


:
On Jul 22, 2016 7:46 AM, "Gordon Levi" <gordon@address.invalid> wrote:
>
> 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.
>
> The second line should be
> if name == "John Cleese" or name == "Michael Palin":
>
> As discussed in recent lengthy thread in this group the following
> line, and hence your statement, is always true -
>
> If "Michael Palin":
> --
> https://mail.python.org/mailman/listinfo/python-list

The easiest way to right this would be to use a tuple like so:

    if name in ('John Cleese', 'Michael Palin'):
        print ('They sound like a gentleman')

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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