Posts: 28
Threads: 16
Joined: Sep 2017
Objective is: to print True when it's a vowel, and False when it's a consonant, WITHOUT using if conditions.
1 2 3 4 5 6 7 8 9 10 |
vowels = [ 'o' , 'i' , 'y' , 'e' , 'a' , 'u' ]
consonants = [ 'b, c, d, f, g, h, j, k, l, m ,n ,p, q, r, s, t, v, w, x, z' ]
def is_vowel(c):
for character in vowels:
print ( True )
for character in consonants:
print ( False )
is_vowel( 'banana' )
|
Here's what I got when I executed the program:
1 2 3 4 5 6 7 |
True
True
True
True
True
True
False
|
This is obviously false because I should get False True False True False True.
Any help?
Posts: 8,165
Threads: 160
Joined: Sep 2016
execute
1 2 3 4 5 6 7 8 9 10 |
vowels = [ 'o' , 'i' , 'y' , 'e' , 'a' , 'u' ]
consonants = [ 'b, c, d, f, g, h, j, k, l, m ,n ,p, q, r, s, t, v, w, x, z' ]
def is_vowel(c):
for character in vowels:
print (character, True )
for character in consonants:
print (character, False )
is_vowel( 'banana' )
|
this will help to see what your script ACTUALLY does
(Sep-21-2017, 09:57 AM)OmarSinno Wrote: Objective is: to print True when it's a vowel, and False when it's a consonant, WITHOUT using if conditions.
1 2 3 4 5 6 7 8 9 10 |
vowels = [ 'o' , 'i' , 'y' , 'e' , 'a' , 'u' ]
consonants = [ 'b, c, d, f, g, h, j, k, l, m ,n ,p, q, r, s, t, v, w, x, z' ]
def is_vowel(c):
for character in vowels:
print ( True )
for character in consonants:
print ( False )
is_vowel( 'banana' )
|
Here's what I got when I executed the program:
1 2 3 4 5 6 7 |
True
True
True
True
True
True
False
|
This is obviously false because I should get False True False True False True.
Any help?
Posts: 33
Threads: 2
Joined: Aug 2017
You are not using "c" which is passed into the function is_vowel()
Posts: 1,150
Threads: 42
Joined: Sep 2016
You have an argument "c" that you pass to the function is_vowel, but where/how do you use it?
Also, compare how you have defined vowels and consonants lists (or what they contain rather).
Posts: 28
Threads: 16
Joined: Sep 2017
Sep-21-2017, 12:54 PM
(This post was last modified: Sep-21-2017, 12:55 PM by OmarSinno.)
Isn't c the string that is supposed to be called later on in the code?
1 2 3 4 5 |
def is_vowel(c):
for character in c:
print (character, True )
for character in c:
print (character, False )
|
I adjusted it to this code, still giving me the same results.
I have realized that when it's finding a vowel, it is printing True 6 times, which is the length of the string 'banana'. Same thing goes for when it finds a consonant.
Unlike this code:
1 2 3 4 5 6 |
def is_vowel2(c):
for character in c:
if character in vowels:
print ( True )
else :
print ( False )
|
Fortunately, I have to do it both ways (using if conditionals and without using them) so I can actually study both. Help?
Posts: 8,165
Threads: 160
Joined: Sep 2016
Sep-21-2017, 02:27 PM
(This post was last modified: Sep-21-2017, 02:29 PM by buran.)
1 2 3 4 5 |
vowels = [ 'o' , 'i' , 'y' , 'e' , 'a' , 'u' ]
def is_vowel2(my_word):
for character in my_word:
print (character in vowels)
is_vowel( 'banana' )
|
or
1 2 3 4 5 |
vowels = [ 'o' , 'i' , 'y' , 'e' , 'a' , 'u' ]
def is_vowel(c):
return c in vowels
for character in 'banana' :
print (is_vowel2(character))
|
|