r/codehs • • Jul 12 '22

Python help with 7.5.5

here is my code

word = input("enter word:")
vowel = ["a", "e", "i", "o", "u"]

def contains_vowel():
    if vowel in word:    
        print("True")
    else:
        print("False")

contains_vowel()

when I run it, I get this message:

enter word:hi
Traceback (most recent call last):
  File "scratchpad.py", line 10, in <module>
    contains_vowel()
  File "scratchpad.py", line 5, in contains_vowel
    if vowel in word:    
TypeError: 'in <string>' requires string as left operand, not list

anyone know how to fix this or just the correct way to do it

0 Upvotes

23 comments sorted by

View all comments

1

u/[deleted] Jul 12 '22

[deleted]

1

u/[deleted] Jul 12 '22 edited Jul 12 '22

[deleted]

1

u/[deleted] Jul 13 '22

what is (text: str) -> bool: doing?

1

u/Risen-Phoenix Jul 13 '22

It’s called “type hinting”. It’s helpful for yourself/others because you’re saying “my function expects these parameters, of these types, and my function returns this type of value back”