0

I have a problem where I have to use a function to output the vowels in a word and output how many vowels there are. I just took a computing course at the local college and am new to this whole thing and its going over my head a bit.

I tried but this is what i got when I ran it:

TypeError: vowel() takes 0 positional arguements but 1 was given

My code:

def vowel ():
  array = []
  counter = 0
  for i in word:
    if i in ("a","e","i","o","u"):
      counter+=1
      array.append(i)
  return (array, counter)

word = input("Enter your word")
function = vowel(word)
print(function)
martineau
  • 119,623
  • 25
  • 170
  • 301

5 Answers5

1

Actually, the error is simple.

When you define the function Vowel, It doesn't recieve any argument.

It should look like this:

def vowel (word):

Hope i can help you :D

Gerard Ramon
  • 67
  • 2
  • 11
1

The number of arguments given in the function definition and function call should be same. In the function definition, you have written def vowel(): but while calling function = vowel(word) you are providing an argument to the function. Hence it throws an error. You can modify it as:

def vowel(word):
   array = []
   counter = 0
   for i in word:
     if i in ("a","e","i","o","u"):
       counter+=1
       array.append(i)
   return (array, counter)

word = input("Enter your word")
function = vowel(word)
print(function)
Charul
  • 450
  • 5
  • 18
0

In function definition, you forgot to provide word

def vowel (word):
  array = []
  counter = 0
  for i in word:
    if i in ("a","e","i","o","u"):
      counter+=1
      array.append(i)
  return (array, counter)


word = input("Enter your word")
function = vowel(word)
print(function)

To read more about Positional arguments see this post Positional argument v.s. keyword argument

Community
  • 1
  • 1
JkShaw
  • 1,927
  • 2
  • 13
  • 14
0

The error is self explanatory. You declared the function vowel to be seeded with 0 arguments.

def vowel ():

and you called it seeding it with one argument:

 function = vowel(word)

what you should have done is:

def vowel (word):
    array = []
    counter = 0
    for i in word:
        if i in ("a","e","i","o","u"):
        counter+=1
        array.append(i)
    return (array, counter)
milouk
  • 171
  • 1
  • 3
  • 11
0

You can use a function and then simple list comprehension:

def vowel(word):
   array = [i for i in word if i in ("a","e","i","o","u")]
   counter = len(array)
   return array, counter

word = input("Enter your word")
function = vowel(word)
print(function)
Ajax1234
  • 69,937
  • 8
  • 61
  • 102