0

I am really new to this coding thing and I orignal wanted to start coding to create bots to automate stuff for me, but to do that I need to learn the basics of coding. I wanted to make a function that can look in a variable for a letter and the print a message. But when I execute the outecome in terminal is none.

vowel = ("aeiou")

def ting(phrase):
    if vowel in phrase:
        print("I have Vowels")

print(ting(input("Enter What you want to say: ")))

I'm sorry if the soultion is really simple but i don't know what to call this problem of mine so i really don't know what to be looking for to fix it.

AMC
  • 2,642
  • 7
  • 13
  • 35
Ed_
  • 1
  • 1
    Does this answer your question? [Why is this printing 'None' in the output?](https://stackoverflow.com/questions/28812851/why-is-this-printing-none-in-the-output). Also, `vowel` is a string and you are looking for it inside the `phrase`. You want to loop over the `vowels` and check if any of them is `in phrase` – Tomerikoo May 07 '20 at 22:32
  • `vowel in phrase` is wrong, as `"aeiou" in "cat"` would be false, although `"cat"` certainly contains a vowel. – chepner May 07 '20 at 22:33

3 Answers3

2

Your if statement will check if the whole string "aeiou" is in the phrase. What you want to do is to check if any such vowel exists in the input text. To do so you have to check each vowel. The for loop below will do the job.

vowels = "aeiou"

def ting(phrase):
    for vowel in vowels:
        if vowel in phrase:
            return "I have vowels"
    return "I have no vowel"

print(ting(input("Enter What you want to say: ")))
maede rayati
  • 756
  • 5
  • 10
0

Two things...

First, instead of print("I have Vowels") write return "I have Vowels". Your print statement outside of the function is asked to print the return value of the function and you are not returning anything, hence the None.

Second, if vowel in phrase: is checking to see if 'aeiou' (the whole string) is in the phrase, not the individual vowels. You need a for loop that loops over the characters in vowels. Something like:

vowels = "aeiou"

def ting(phrase):
    for vowel in vowels:
        if vowel in phrase:
            return "I have Vowels"
    return "I have no Vowels"

print(ting(input("Enter What you want to say: ")))
lovefaithswing
  • 1,510
  • 1
  • 21
  • 37
0

You want to know if any vowel is in the phrase, and fortunately Python has a any function.

vowels = "aeiou"

def ting(phrase):
    if any(vowel in phrase for vowel in vowels):
        print("I have Vowels")

print(ting(input("Enter What you want to say: ")))
Guimoute
  • 4,407
  • 3
  • 12
  • 28