Chunky by FelipeFS
Chunky by FelipeFS
GPWiki.org
It is currently Wed Nov 26, 2014 9:18 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sat Dec 07, 2013 3:45 pm 
Rookie

Joined: Sat Dec 07, 2013 3:03 pm
Posts: 2
So I've been trying to get this Python Pyglatin translator to work,

pyg = 'ay'

original = raw_input('Enter a word:')
word = original.lower()
if len(original) > 0 and original.isalpha():
print word
if word [0] == "a" or "e" or "i" or "o" or "u":
print "vowel"
else:
print "consonant"
else:
print 'empty'

Whenever I input a word that starts with a vowel it tells me "vowel", which is good. But whenever I input a word that starts with a consonant it tells me "vowel" still. Could anybody tell me why.

It's probably a beginners mistake, but then again, I'm a beginner.

Any help would be appreciated,
FootsoreCord760,


Top
 Profile  
 
PostPosted: Sat Dec 07, 2013 4:09 pm 
Digerati

Joined: Thu Sep 09, 2004 1:17 pm
Posts: 1819
Location: burrowed
Hey FootsoreCord760, welcome to the forums :)

I'm not familiar with python, but what stands out is your if-statement

FootsoreCord760 wrote:
if word [0] == "a" or "e" or "i" or "o" or "u":


I dont know if that is legal in python. Usually you chain statements like this

Code:
if word[0]== "a" or word[0] == "e" or ...


Also make sure your word variable holds the correct word by just printing it after you assign it.

hope that helps

_________________
Long pork is people!

wzl's burrow


Top
 Profile  
 
PostPosted: Sat Dec 07, 2013 7:19 pm 
Rookie

Joined: Sat Dec 07, 2013 3:03 pm
Posts: 2
Thanks a lot weezl! I've been taking a few courses on Codecademy and they never told me that I had to repeat the statement like that like that.

Thanks again for helping a newbie!
FootsoreCord760,


Top
 Profile  
 
PostPosted: Sat Dec 07, 2013 8:01 pm 
Grand Optimizer

Joined: Sun Oct 16, 2011 3:09 pm
Posts: 367
Location: Here (where else?)
The more pythonic form is
Code:
if word[0] in ["a", "e", "i", "o", "u"]:

_________________
My project: Messing about in FreeRCT, dev blog, and IRC #freerct at oftc.net


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron

Powered by phpBB® Forum Software © phpBB Group