if-else-then

TuPLaD tuplad at gmail.com
Sat Sep 11 08:34:42 EDT 2004


Thank you very much !

But i got one more question, i was googling in python sites, and i
found a site where he he a code like this :


if user type: n, no, nop, nope then print 'You canceled'
else
if user type: y, ye, yes, yep then print 'We are beginning'


How do i do that ?



Phil Frost <indigo at bitglue.com> wrote in message news:<mailman.3180.1094859861.5135.python-list at python.org>...
> "=" and "==" are two different operators in Python. "=" is the asignment
> operator; it asigns values to names. "==" is the equality operator; it
> returns true if its operands are equal.
> 
> Also, to compare   name   to a string, the string must be in quotes.
> Without quotes, python will look for a varable named "Stickie".
> 
> Furthermore, defining main won't make it run. A common idiom is to check
> __name__ and run main. If the file is being run as a program, as opposed
> to being imported as a module, __name__ will be "__main__".
> 
> Also, I don't see need for the "n" parameter, or the time.sleep(). I
> have removed them.
> 
> Here is your program with these points applied:
> 
> #===========
> 
> def main():
>     name = raw_input("Please enter your name: ")
>     if name == "Stickie":
>         print 'Yo masta', name
>     else:
>         print "Your name is", name
> 
> if __name__ == '__main__':
>     main()
> 
> #===========
> 
> On Fri, Sep 10, 2004 at 04:34:58PM -0700, TuPLaD wrote:
> > Hi, i got the following script:
> > 
> > name = raw_input("Please enter your name: ")
> > print "Your name is", name
> > 
> > but i want it that way:
> > 
> > if 
> > name = Stickie
> > then
> > print "You be di man"
> > 
> > how do i do it ?
> > 
> > This i what i have from a tutorial, but with syntax errors i dont know
> > what im doing wrong :(
> > 
> > #!C:\Python23\python.exe
> > # My first Python Application !
> > # By TuPLaD
> > # [email]spawnxx at pandora.be[/email]
> > 
> > import time
> > def main(n):
> >     name = raw_input("Please enter your name: ")
> >     if name = Stickie:
> >         print 'Yo masta', name
> >     else:
> >         print "Your name is", name
> > 
> > time.sleep(5)
> > 
> > what should i do ?



More information about the Python-list mailing list