Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 13th, 2005, 11:55 AM   #1
arod199113
Programmer
 
arod199113's Avatar
 
Join Date: Feb 2005
Posts: 86
Rep Power: 0 arod199113 is an unknown quantity at this point
Question if elif else

say i had a program like this:

a = raw_input("Type either ball, cat, dog, or eat:")
if a == "ball":
     print "abcd"
elif a == "cat":
     print "abcd"
elif a == "dog":
     print "wxyz"
elif a == "eat":
     print "wxyz"


basically if you were type ball or cat it would print abcd
and if you were to type dog or eat it would print wxyz
is it possible to not have to repeat typing: print "abcd" 2 times
like:
if a = "ball" or "cat":
print "abcd"
i know its not done like that i just wanna know if it can be done somehow

Last edited by arod199113; Feb 13th, 2005 at 11:58 AM.
arod199113 is offline   Reply With Quote
Old Feb 13th, 2005, 12:42 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8 Ooble is on a distinguished road
Actually, what you've done is pretty much right:
if a == "ball" or a == "cat":
    print "abcd"
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 13th, 2005, 8:27 PM   #3
arod199113
Programmer
 
arod199113's Avatar
 
Join Date: Feb 2005
Posts: 86
Rep Power: 0 arod199113 is an unknown quantity at this point
thanks
i just didnt know exactly how to do it
arod199113 is offline   Reply With Quote
Old Feb 13th, 2005, 9:03 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8 Ooble is on a distinguished road
Enjoy yourself. If you want a book on Python, this one's not only good, but free too:

How to Think Like a Computer Scientist: Learning with Python
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:57 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC